Training 2 - E title
lily has been a very good friend xiaoou333 empty, he thought something did not make sense of things, is an article of statistics the total number of different words. Below you xiaoou333 mission is to help solve this problem.
Input
Multiple sets of data, each line, each is a small article. Each small articles are lowercase letters and spaces, no punctuation, # indicates the end of input is encountered.
Output
Each group output only an integer, which make the trip alone, the total number of different words in an article of the integer representative.
Sample Input
you are my friend
Sample Output
4
#pragma warning (disable:4996)
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#define inf 0X3f3f3f3f
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e5 + 5;
set<string> s;
int main()
{
string str;
while (getline(cin, str) && str != "#")
{
s.clear();
string tmp = "";
s.insert(tmp);//防止有空输入
for (int i = 0; str[i] != '\0'; i++)
{
if (str[i] == ' ')
{
s.insert(tmp);
tmp = "";
}
else
tmp += str[i];
}
s.insert(tmp);
printf("%lld\n", (ll)s.size() - 1);
}
return 0;
}
Idea:
When the string and char conversion, can directly use the + operator.
Note to determine whether free input.