Andy's First Dictionary
程序员文章站
2024-03-18 21:58:58
...
题目大意:给出不超过5000行的英文,按照字典序打印所有单词,若一个单词多次出现,那么只打印一次,并且所有单词都要转成小写单词。
思路:set的使用,每次读取一个字符串,将每一个字符串变成小写字符,如果出现标点,则将其变为空格,最后再用stingstream输入一次即可
代码:
#include <set>
#include <sstream>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
string s , t;
set < string > dirt;
int main(void)
{
while(cin >> s)
{
//isalpha用于判断参数是不是一个字母字符,tolowwer用于将字母字符转成小写
for(int i = 0 ; i < (int)s.length() ; ++ i)
if(isalpha(s[i])) s[i] = tolower(s[i]);
else s[i] = ' ';
stringstream ss(s);
while(ss >> t) dirt.insert(t);
}
//auto会自动识别i的类型
for(auto i : dirt) cout << i << endl;
return 0;
}
上一篇: Team Queue
下一篇: R+W 618.6740.425
推荐阅读
-
Andy's First Dictionary
-
You must call removeView() on the child's parent first 的处理。
-
ViewGroup的addView异常You must call removeView() on the child's parent first
-
The specified child already has a parent. You must call removeView() on the child‘s parent first.
-
The specified child already has a parent. You must call removeView() on the child's parent first.
-
The specified child already has a parent. You must call removeView() on the child's parent first,
-
The specified child already has a parent. You must call removeView() on the child's parent first
-
Head First Design Pattern - 3 - This week's interview: Confe
-
Head First Design Pattern - 4 - This week's interview: Facto
-
Andy's First Dictionary