2个点超时,sad。。。
注意
1.大写字母的ascii值比小写字母小32
2.字符数组的赋值用strcpy()函数
strcpy(字符数组1,字符数组2) --即将后面的赋值给前面的
#include <cstdio>
#include <map>
#include <string>
#include <string.h>
using namespace std;
char c[1048576];
char ans[1048576];
char tmp[1048576];
int times=0;
map <string,int> mp;
int main(){
freopen("in.txt","r",stdin);
gets(c);
int cnt=0;
for(int i=0;i<=strlen(c);){
if(c[i]>='0'&&c[i]<='9' || c[i]>='a'&&c[i]<='z' || c[i]>='A' && c[i]<'Z'){
if(c[i]>='A' && c[i]<'Z'){
tmp[cnt++]=c[i++]+32;
}else{
tmp[cnt++]=c[i++];
}
}else if(c[i]==' ' || c[i]=='\0'){
tmp[cnt]='\0';
if(strlen(tmp)!=0){
map <string,int>::iterator it=mp.find(tmp);
if(it!=mp.end()){
it->second++;
}else{
mp[tmp]=1;
}
}
i++;
cnt=0;
if(mp[tmp]>times){
times=mp[tmp];
//strcoy(字符数组1,字符数组2)即将字符数组2的内容复制到字符数组1中
strcpy(ans,tmp);
}
}else{
i++;
}
}
printf("%s %d\n",ans,times);
return 0;
}