统计单词数量(按出场顺序):大小写不分
#include<bits/stdc++.h>
using namespace std;
string s[100];
int t[100];
void zh(string &s){ //转成小写
int len=s.size();
for(int i=0;i<len;i++){
if(s[i]>=‘A’&&s[i]<=‘Z’)s[i]+=32;
}
}
int main(){
freopen(“926.in”,“r”,stdin); //文件读入
int i,j=0;
string s1;
while(cin>>s1){ //无固定数量字符串
i=0;
zh(s1);
while(i<j){
if(s[i]!=s1)i++; //按出场顺序遍历
else break;
}
if(i==j)j++;
s[i]=s1;
t[i]++;
}
for(i=0;i<j;i++){
cout<<t[i]<<":"<<s[i]<<endl;
}
return 0;
}
统计单词数量
最新推荐文章于 2018-10-26 11:49:12 发布