题解
水 ...
代码
法一
#include <bits/stdc++.h>
using namespace std ;
#define rg register
typedef long long ll ;
int main ( ) { //freopen( "F:\\in\\set.txt" , "r" , stdin ) ;
string s , t ;
set<string> st ;
st.clear() ;
while ( cin >> s ) {
t = "" ;
rg int len = s.size() ;
for ( rg int i = 0; i < len ; ++i ) {
if ( isalpha( s[i] ) )
t += tolower( s[i] ) ;
else {
st.insert( t ) ;
t = "" ;
}
}
st.insert( t ) ;
}
for ( auto it = st.begin() ; it != st.end() ; ++it ) {
if ( *it != "" ) cout << *it << endl ;
}
return 0 ;
}
法二
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <sstream>
using namespace std;
int main()
{
string s, buf;
set<string>a;
while(cin>>s)
{
for(int i=0;i<s.length();i++)
{
if(isalpha(s[i]))
s[i] = tolower(s[i]);
else
s[i] = ' ';
}
stringstream ss(s);
while(ss >> buf)
{
a.insert(buf);
}
}
for(set<string>::iterator it= a.begin();it!=a.end();it++)
{
cout<<*it<<endl;
}
return 0;
}
题目
Sample Input
样例输入①
a a a a a a a a, a a a a a a.
a a a a b a a a. a? a!!!
样例输入②
Adventures in Disneyland
Two blondes were going to Disneyland when they came to a fork in the
road. The sign read: “Disneyland Left.”
So they went home.
Sample Output
样例输出①
a
b
样例输出②
a
adventures
blondes
came
disneyland
fork
going
home
in
left
read
road
sign
so
the
they
to
two
went
were
when
Hint
输入可能包含标点符号,但标点符号显然不能算作单词的一部分。