HDU-2072 单词数 水题一枚
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2072
map判重即可:
1 //STATUS:G++_AC_0MS_376KB 2 #include<stdio.h> 3 #include<stdlib.h> 4 #include<string.h> 5 #include<math.h> 6 #include<iostream> 7 #include<string> 8 #include<algorithm> 9 #include<vector> 10 #include<queue> 11 #include<stack> 12 #include<map> 13 using namespace std; 14 #define LL long long 15 #define Max(a,b) ((a)>(b)?(a):(b)) 16 #define Min(a,b) ((a)<(b)?(a):(b)) 17 #define mem(a,b) memset(a,b,sizeof(a)) 18 #define lson l,mid,rt<<1 19 #define rson mid+1,r,rt<<1|1 20 const int MAX=100010,INF=0x3f3f3f3f; 21 22 map<string,int> q; 23 char s[MAX]; 24 25 int main() 26 { 27 // freopen("in.txt","r",stdin); 28 int i,j,len,ans; 29 while(gets(s)!=NULL && s[0]!='#') 30 { 31 ans=0; 32 q.clear(); 33 len=strlen(s); 34 for(i=0;i<len;i=j+1){ 35 while(s[i]==' ' && i<len)i++; 36 if(i==len)break; 37 for(j=i;s[j]!=' ' && j<len;j++); 38 s[j]='\0'; 39 if(!q[s+i]){ 40 q[s+i]=1; 41 ans++; 42 } 43 } 44 45 printf("%d\n",ans); 46 } 47 return 0; 48 }