hdu 2072(单词数)
思路:
需特别注意数据有 2个单词中间有多个空格 结尾也有空格
#include<stdio.h> #include<iostream> #include<map> #include<string.h> #include<string> using namespace std; int main() { char ch[1000000]; string str,l; int m,i,a,len,q; while(gets(ch)&&ch[0]!='#') { a=0;m=0;q=0;len=0; map<string,int>mp; map<string,int>::iterator p; l=ch; i=0; while(ch[i]==' ')i++; if(i==strlen(ch)){printf("0\n");continue;} for(i;i<strlen(ch)+1;i++) { if(ch[i]>='a'&&ch[i]<='z') { len++; q=0; } else { if(q==0) { a=i-len; str=l.substr(a,len); mp[str]=1; len=0; q=1; } } } printf("%d\n",mp.size()); } return 0; }