Languages<stringstream的使用+map集合的使用>
来源:互联网 发布:navicat for mysql破解 编辑:程序博客网 时间:2024/05/24 04:59
Languages
The Enterprise has encountered a planet that at one point had been inhabited. The only remnant from the prior civilization is a set of texts that was found. Using a small set of keywords found in various different languages, the Enterprise team is trying to determine what type of beings inhabited the planet.
The first line of input will be N (1 ≤ N ≤ 100), the number of different known languages. The next N lines contain, in order, the name of the language, followed by one or more words in that language, separated with spaces. Following that will be a blank line. After that will be a series of lines, 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, or hyphens, 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 sample text will contain keywords from multiple languages. The sample text may contain additional punctuation (commas, periods, exclamation points, semicolons, question marks, and parentheses) and spaces, all of which serve as delimiters separating keywords. Sample text may contain words that are not keywords for any specific language. Keywords should be matched in a case-insensitive manner.
For each line of sample text that follows the blank line separating the defined languages, print a single line that identifies the language with which the sample text is associated.
4Vulcan throks kilko-srashiv k'etwelRomulan Tehca uckwazta Uhn NeemastaMenk e'satta prah ra'sataRussian sluchilosDif-tor heh, Spohkh. I'tah trai k'etwelUhn kan'aganna! Tehca zuhn ruga'noktan!
VulcanRomulan
#include<cstdio>#include<cctype>#include<iostream>#include<stack>#include<map>#include<cstring>#include<string>#include<sstream>#include<queue>using namespace std ;int main() { int n; cin>>n; string a,b,c; map<string,string> q; getchar();//这个getchar()不能省,如果省略了,相当于少输入了一行数据,因为getline遇到回车直接跳下一步了 for(int i=0;i<n;i++){ getline(cin,a); stringstream txt(a); txt>>b; while(txt>>c){//这里也是之前没考虑到的问题,一定要讲所有的单词同一大小写,注意,是单词统一大小写,语言的名字不管他 for(int i=0;i<c.size();i++) { if(c[i]>='A'&&c[i]<='Z') c[i]+=32; } q[c]=b;//把每个单词都归属于一个语言. } } while(getline(cin,a)){ for(int i=0;i<a.size();i++)//同一分割符的标准,全部改成空格分隔; if (a[i]==','||a[i]=='.'||a[i]=='!'||a[i]==';'||a[i]=='?'||a[i]=='('||a[i]==')') a[i]=' '; stringstream txt1(a); string d; while(txt1>>d){ for(int i=0;i<d.size();i++)//每一句话里面的单词也都要同一大小写. { if(d[i]>='A'&&d[i]<='Z') d[i]+=32; } //cout<<d<<endl; if(q.count(d)){//如果找到有一个单词属于上面输入的语言之一,就直接输出。 cout<<q[d]<<endl; break; } } } return 0 ;}
- Languages<stringstream的使用+map集合的使用>
- Map集合的使用
- Map集合的使用
- map集合的使用
- map集合的使用
- stringstream对象的使用
- stringstream对象的使用
- c++: stringstream的使用
- stringstream 的使用注意事项
- stringstream的函数使用
- stringstream的使用
- CSU 1826:Languages(stringstream的应用)
- C++ Map集合的使用
- 关于Map集合的使用
- stringstream,istringstream,ostringstream的使用
- CSU 1826 Languages map和stringstream
- Bribing FIPA(树形DP)输入难,学会stringstream的用法,map的使用
- Map集合的putAll()方法的使用。
- 负载均衡汇总
- 支持多文件、多格式远程上传的FTP实战案例
- A
- POJ:Currency Exchange
- cocosx项目移植到Xcode中经历的坑 (更新中...)
- Languages<stringstream的使用+map集合的使用>
- Java中的深拷贝(深复制)和浅拷贝(浅复制)
- 如何取url中的参数
- IOS 身份证校验
- C++写时拷贝(测试用例String类)
- No adapter for handler [public boolean com.fuying.assure.user.login.action.UserManageAction.validIdN
- java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $
- 关于descriptionWithLocale和NSLog数组/字典时中文显示unicode
- 总结几种排序算法(一)---冒泡排序