AcWing 3615. 单词个数统计
原题链接
简单
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
const int N = 1e6+10;
int t,n,m,k,l,r,op,x,y;
int f[N];
bool flag;
string str;
char last;
int cnt,word;
void solve(){
getline(cin,str);
str.push_back(' ');
for(char ch:str){
if(isalpha(ch)){
if(ch>='A'&&ch<='Z')ch+=32;
cnt++;
f[(int)ch]++;
}
if(ch==' '){
if(last!=' ')word++;
}
last=ch;
}
x = *max_element(f+'a',f+'z');
cout<<cnt<<"\n"<<word<<"\n";
for(int i = 'a';i<'z';i++){
if(f[i]==x){
cout<<(char)(i)<<" ";
}
}
cout<<"\n"<<x;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}