Problem Statement
Given a string ,Write a program to print letter followed by it’s frequency.
Input Format
input must be in string
Output Format
count the characters.. and print the alphabet and its count adjacently
Sample Input
aaabcc
Sample Output
a3b1c2
My Code:
#include <iostream>
#include<string.h>
using namespace std;
int main(void) {
int hash[26]={0};
char a[100];
cin>>a;
for(int i=0;i<strlen(a);i++)
{
hash[a[i]-97]++;
}
for(int i=0;i<26;i++)
{
if(hash[i]>=1)
{
char x=i+97;
cout<<x<<hash[i];
}
}
return 0;
}
My Code:
#include <iostream>
#include<string.h>
using namespace std;
int main(void) {
int hash[26]={0};
char a[100];
cin>>a;
for(int i=0;i<strlen(a);i++)
{
hash[a[i]-97]++;
}
for(int i=0;i<26;i++)
{
if(hash[i]>=1)
{
char x=i+97;
cout<<x<<hash[i];
}
}
return 0;
}