Andy's First Dictionary
Andy's First Dictionary
SCUACM2022集训前训练-数据结构 - Virtual Judge (vjudge.net)
stringstream
把单词从字符串里分离出来,可以先把字符串里的非字母字符变成 空格, 再放入 stringstream 中,再读 stringstream 这样单词就被分离出来了
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <sstream>
using namespace std;
typedef long long ll;
set<string> st;
int main()
{
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
string s;
while(cin >> s)
{
for (int i = 0; i < s.size(); i++)
{
if (isalpha(s[i]))
s[i] = tolower(s[i]);
else
s[i] = ' ';
}
stringstream ss(s);
while(ss >> s)
st.insert(s);
}
for (auto str : st)
cout << str << endl;
return 0;
}