UVA - 10815 - Andy's First Dictionary
来源:互联网 发布:淘宝云客服培训 编辑:程序博客网 时间:2024/06/05 09:09
题意:
输入N行数据,将其中所有单词抽出,形成一个正序字典;最后输出整个字典。
注意:
① 不会大小写,统一输出小写;
② 非字母字符不能输出
③ 单词多长多短,只要隔开,就是一个单词。
思路:
以“行”为单位,进行处理。
① 输入一行,保存到char*中
② char*转string
③ 大写字母换成小写
④ 非字母字符换成空格
⑤ istringstream流逐个输出各单词
⑥ 保存到set中;set自动去重及正序化。(注:multiset可重复)
最后输出整个set。
注意:
① set自动去重及正序化;而multiset可重复
② 多用英语表达。
#include <iostream>#include <sstream>#include <set>#include <algorithm>#include <string>#include <stdio.h>using namespace std;// #define LOCAL_TESTint main(){#ifdef LOCAL_TESTfreopen("..\\in.txt", "r", stdin);freopen("..\\out.txt", "w+", stdout);#endif// ------- Solution by using vector + Sync(false)std::ios::sync_with_stdio(false);std::cin.tie(0);char strIn[210];set <string> setRes;while ( gets(strIn) ){// Transform char* To string. string strLine(strIn);// Using transform To LOWER all charactors of the string. transform(strLine.begin(), strLine.end(), strLine.begin(), ::tolower);// Set all non-letter To blank space. for ( string::iterator it=strLine.begin(); it != strLine.end(); it++ )if ( !isalpha(*it) )*it = ' ';// Use istringstream to separate all words,// Meanwhile, store into setRes(SET)istringstream strStream(strLine);string strOut;while ( strStream >> strOut )setRes.insert(strOut);} // end while// Output all words in setRes(SET).// PS, set is sorted alphabetically, automaticallyfor ( set<string>::iterator it=setRes.begin(); it!=setRes.end(); it++ )cout << *it <<endl;return 0;}
0 0
- UVa OJ 10815-Andy's First Dictionary
- uva 10815 Andy's First Dictionary
- UVa 10815 - Andy's First Dictionary
- UVA 10815 - Andy's First Dictionary
- uva-10815 - Andy's First Dictionary
- UVa 10815 - Andy's First Dictionary
- UVA 10815 Andy's First Dictionary
- UVa 10815 - Andy's First Dictionary
- UVA 10815 Andy's First Dictionary
- UVa-10815 - Andy's First Dictionary
- UVA 10815 - Andy's First Dictionary
- uva -- 10815 Andy's First Dictionary
- UVA 10815 Andy's First Dictionary
- uva 10815 Andy's First Dictionary
- UVa 10815 - Andy's First Dictionary
- uva - 10815 - Andy's First Dictionary
- UVA 10815 Andy's First Dictionary
- Uva 10815 - Andy's First Dictionary
- 菜鸟 该如何应对服务器被黑
- 50. PHP switch
- Rescue The Princess 山东省赛题 求三角形顶点 atan2求解
- P52 第34题 输入两个整数或三个整数得到最大值
- 省赛选拔赛——个人赛第一场
- UVA - 10815 - Andy's First Dictionary
- Eclipse Maven创建Web项目
- ViewPager实现的切换动画
- MySQL与Oracle的大小写问题
- 【Python】科学计算环境 —— Anaconda
- Bind9 日志
- cocos2d-x 无法打开文件“libbox2d.lib”解决
- android studio中导入第三方jar包和第三方库文件的方法
- JavaScript里面的坑(一)——读《JavaScript高级程序设计》有感