Qn: Write the C++ program to print letter and its number of times
Input: aaabcddgaapp Output: a3bcd2ga2p2
-By Srishti, Last Update On 12th June,2019 09:25 pm
#include<iostream.h>
#include<conio.h>
#include<string.h>
int main(){
int i,p = 0,count = 1;
char str[100];
cout<<"Enter your string:";
cin>>str;
for (i = 0; i < strlen(str); i++) {
if (i + 1 < strlen(str)) {
if (str[p] == str[i + 1]) {
count++;
} else {
if (count == 1) {
cout<<str[p];
} else {
cout<<str[p]<<count;
}
p = i + 1;
count = 1;
}
} else {
if (count == 1) {
cout<<str[p];
} else {
cout<<str[p]<<count;
}
break;
}
}
return 0;
}
Input:
Enter your string: aaabcddgaapp
Output:
a3bcd2ga2p2
Enter your string: aaabcddgaapp
Output:
a3bcd2ga2p2
Pgcomments
இது பற்றிய தங்களின் கருத்துகளை இங்கே பதிவிடுங்கள் . இது பயனுள்ளதாக விரும்பினால் மற்றவர்களுக்கும் இதை share செய்யுங்கள்.
Comments