题目:http://acm.hdu.edu.cn/showproblem.php?pid=2072
C语言的方式,gets()读入空格
#include<stdio.h>
#include<string.h>
#define N 10000
char article[N],tmp[101],word[N][101];
int main()
{ int len,pos,k,cnt;
while(gets(article)!=NULL)
{
if(article[0]=='#') break;
cnt=0;
len=strlen(article);
pos=0;
while(pos<len)
{
sscanf(article+pos,"%s",tmp);
for(k=0;k<cnt;k++)
if(strcmp(word[k],tmp)==0)
break;
if(k==cnt)
strcpy(word[cnt++],tmp);
pos+=strlen(tmp)+1;
}
printf("%d\n",cnt);
}return 0;
}
************************************************c++使用set挺给力
#include <set>
#include <string>
#include <iostream>using namespace std;
int main(void)
{
set <string> st;
string s = "";
while ((c = cin.get()) != '#')
{
s += c;
while (c != '\n')
{
while ((c = cin.get()) != ' ' && c != '\n')
s += c;
if (s.length()) st.insert(s);
s = "";
}
cout << st.size() << endl;
st.clear();
}
return 0;
}