CSUOJ 1826 Languages map+stringstream
Description
The Enterprise has encountered a planet that at one point had been inhabited. The onlyremnant from the prior civilization is a set of texts that was found. Using a small set of keywordsfound in various different languages, the Enterprise team is trying to determine what type of beingsinhabited the planet.
Input
The first line of input will be N (1 ≤ N ≤ 100), the number of different known languages. Thenext N lines contain, in order, the name of the language, followed by one or more words in thatlanguage, separated with spaces. Following that will be a blank line. After that will be a series oflines, each in one language, for which you are to determine the appropriate language.Words consist of uninterrupted strings of upper or lowercase ASCII letters, apostrophes, orhyphens, as do the names of languages. No words will appear in more than one language.No line will be longer than 256 characters. There will be at most 1000 lines of sample text.Every sample text will contain at least one keyword from one of the languages. No sampletext will contain keywords from multiple languages. The sample text may contain additionalpunctuation (commas, periods, exclamation points, semicolons, question marks, and parentheses)and spaces, all of which serve as delimiters separating keywords. Sample text may contain wordsthat are not keywords for any specific language.Keywords should be matched in a case-insensitive manner.
Output
For each line of sample text that follows the blank line separating the defined languages, print asingle line that identifies the language with which the sample text is associated.
Sample Input
4 Vulcan throks kilko-srashiv k'etwel Romulan Tehca uckwazta Uhn Neemasta Menk e'satta prah ra'sata Russian sluchilos Dif-tor heh, Spohkh. I'tah trai k'etwel Uhn kan'aganna! Tehca zuhn ruga'noktan!
Sample Output
Vulcan Romulan
Hint
题意:告诉你每种语言的一些单词,再给一个段话,判断是用什么语言写的。又一次感受到C++ stl的强大思路:使用 stringstream类读取字符串,通过>>操作分离出单词,然后进行判断
#include<stdio.h> #include<iostream> #include<algorithm> #include<sstream> #include<string> #include<string.h> #include<ctype.h> #include<map> using namespace std; map<string, string>m; void lower(string &s) { for (int i = 0; i < s.length(); i++) { s[i] = tolower(s[i]); } } int main() { int T; m.clear(); string a, b,name,s; cin >> T; getchar(); for (int i = 0; i < T; i++) { getline(cin, a); stringstream ss(a); ss >> name; while (ss >> b) { lower(b); m[b] = name; } } while (getline(cin, s)) { string tmp; for (int i = 0; i < s.length(); i++) { if (s[i] == ',' || s[i] == '.' || s[i] == '!' || s[i] == ';' || s[i] == ' ? ' || s[i] == '(' || s[i] == ')') s[i] = ' '; } stringstream ss1(s); while (ss1 >> tmp) { lower(tmp); if (m.count(tmp)) { cout << m[tmp] << endl; break; } } } return 0; } /********************************************************************** Problem: 1826 User: leo6033 Language: C++ Result: AC Time:68 ms Memory:2348 kb **********************************************************************/
- CSU 1826:Languages(stringstream的应用)
- 文章标题 CSU 1826: Languages(字符串的处理+map)
- 【杭电2015年12月校赛H】【模拟 STL-MAP STL-SET stringstream】Study Words 从article中提取中10个没有学过的频率最高单词
- 【ny-oj】-1112-求次数(STL,string&map)
- CSUOJ 1808 地铁(用map储存DP数组的DP)
- 大量访问Google的map URL返回Respon不要直接用String接,需要用Stream去接
- 【HDU-oj】-6015-Skip the Class(map string vector)
- 【杭电oj】2072 - 单词数(STL - string & map)
- 【UKIEPC2015 C】【STL set map stringstream】Conversation Log 网络审查 被所有人都说过的话 map套set法+人哈希法
- CSUOJ 1341 String and Arrays
- 将Map<String, List<Map<String,Object>>>进行排序
- 足球赛确定淘汰赛名单-map<string, int>问题
- stirng转json,String转成List<Map<String,object>>,然后转成json
- sstringstream
- c++ stringstream
- C++的sstream标准库-istringstream/ostringstream/stringstream3个类的介绍和使用方法的总结
- java8 lambda小试牛刀,利用Stream把list转map,并将两个list的数据对象合并起来
- String转换到Map结构
- Windows 8技巧:关于windows 8的文件管理 File创建和String Stream Buffer方式读写的