开始用c做,指针的知识不敢乱用,gets()这个函数有问题,据说已经被停用了。
最终用的还是c++,用了set数组模板,用了sstream的输入流(一直担心这种方式处理太慢而不能AC。
#include<iostream>
#include<string>
#include<set>
#include<sstream>
using namespace std;
set<string>tmp;
main(){
string input,row;
while(getline(cin,row)&&row!="#"){
tmp.clear();
stringstream str(row);
while (str>>input)
tmp.insert(input);
cout<<tmp.size()<<endl;
}
}
**自顶向下,getline(cin,row)
stringstream str(row)
(str>>input)
row继承了cin的功能,又传给str,所以str也有了cin的功能(不严谨的分析**
顺带贴上一个强迫症博主的思路(真严谨)
HDU2072