getline可以读入整行,以回车作为结尾,故如果输入形式是一个整数n,之后n行含有空格的串,要先进行getline(cin,s);读取完整数n后的空格。
头文件是sstream,string
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
map<string,int>m;
int main()
{
getline(cin,s);
string str;
stringstream newcin(s);
//以空格为分隔,隔出每个string
while (newcin>>str){
m[str]++;
}
cout<<m.size();
return 0;
}