string count occurrences c++
#include <algorithm>
std::string s = "a_b_c";
size_t n = std::count(s.begin(), s.end(), '_'); //n=2
string count occurrences c++
#include <algorithm>
std::string s = "a_b_c";
size_t n = std::count(s.begin(), s.end(), '_'); //n=2
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]!='\0'){
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;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us