题意:输入一个文本内容,将每个单词按照字典顺序输出,必须是小写字母。
题解:
刚学会的重定向,交上去忘记注释了,WA了一发。
isalpha()函数:判断字符是否为英文字母,若为英文字母,返回非0(小写字母为2,大写字母为1)。若不是字母,返回0。
tolower()函数:将字母转化为小写字母。
c++中,stringstream ss(str);表达的是什么意思??stringstream详细介绍用法点击这里
读取str中的单字,比如"hello world" ,就会读取hello和world。
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include<sstream>
#define ms(arr) memset(arr, 0, sizeof(arr))
typedef long long ll;
using namespace std;
const int inf = 2147483647;
const int MAX = 1e5;
const int mod = 1e3;
set<string>z;
int main()
{
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
string s1,buf;
while(cin>>s1)
{
int len=s1.length();
for(int i=0;i<len;i++)
{
if(isalpha(s1[i]))
{
s1[i]=tolower(s1[i]);
}
else
{
s1[i]=' ';
}
}
stringstream ss(s1);
while(ss>>buf)
{
z.insert(buf);
}
}
for(set<string>::iterator it=z.begin();it!=z.end();it++)
{
cout<<*it<<endl;
}
return 0;
}