the reason of reason:1、很多概念都不熟悉,字符串的很多函数都不会用。
字符串gets不能用在char上。
2、敲的时候bug太多了,调试了很久,花了将近40min没提交。
代码:
#include <iostream>
#include<stdio.h>
#include <string.h>
#include <map>
using namespace std;
char s1[1000];
char s2[1000];
struct ttt{
char a[100];
int s;
};
map<string,int>qq;
ttt bb[500];
int cmp1(ttt a,ttt b){
if(a.s!=b.s)
return a.s>b.s;
else
return a.a[0]<b.a[0];
}
int main(){
freopen("in.txt","r",stdin);
int i,j,k,l1,l2,f1,f2,f3,t1,t2,t3;
memset(bb,0,sizeof(bb));
t2=0;
while(gets(s1)){
for(i=0;i<strlen(s1);i++){
if(s1[i]=='#')break;
if((s1[i]>='a'&&s1[i]<='z')||(s1[i]>='A'&&s1[i]<='Z')||s1[i]=='_'){
if(s1[i]>='A'&&s1[i]<='Z')
s1[i]=s1[i]+32;
s2[t1++]=s1[i];
if(t1>14){
if(qq[s2]==0){
t2++;
qq[s2]=t2;
strcpy(bb[t2].a,s2);
bb[t2].s=1;
}else{
bb[qq[s2]].s++;
}
while((s1[i]>='a'&&s1[i]<='z')||(s1[i]>='A'&&s1[i]<='Z')||s1[i]=='_'){
t1=0;
i++;
}
i--;
}
if(i==strlen(s1)-1&&t1!=0){
if(qq[s2]==0){
t2++;
qq[s2]=t2;
strcpy(bb[t2].a,s2);
bb[t2].s=1;
}else{
bb[qq[s2]].s++;
}
}
}else{
if(t1!=0){
if(qq[s2]==0){
t2++;
qq[s2]=t2;
strcpy(bb[t2].a,s2);
bb[t2].s=1;
}else{
bb[qq[s2]].s++;
}
//cout << s2 << endl;
}
t1=0;
memset(s2,0,sizeof(s2));
}
}
sort(bb+1,bb+1+t2,cmp1);
for(i=1;i<=t2;i++)
cout << bb[i].a << " " << bb[i].s << endl;
}
return 0;
}