Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

letter occurrence in string c++

#include<bits/stdc++.h>
using namespace std;

 
int main(){
  int cnt=0;
   string s;
   cin>>s;
   int alpha[26]={0},i=0,j;
   while(s[i]!=''){
     if(s[i]>='a'&& s[i]<='z'){
       j=s[i]-'a';
       alpha[j]++;
     }
     i++;
   }
  for(int i=0;i<26;i++){
    if(alpha[i]>=1){
      cout<<(char)(i+'a')<<" : "<<alpha[i]<<endl;
    }
  }
  
  return 0;
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #letter #occurrence #string
ADD COMMENT
Topic
Name
9+5 =