2017CSU暑假集训 Languages
来源:互联网 发布:罗技逆战宏编程 编辑:程序博客网 时间:2024/05/16 06:54
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
题意:
这里就是STL里面的map和stringstream,getline的结合使用,将每一个词的对应键值设置为所属语言
代码:
#include<map>#include<cstring>#include<sstream>#include<iostream>#include<cstdio>using namespace std;int main(){ int t; string help1,lei,word; map<string,string> m; cin>>t; getchar(); for(int i = 0;i<t;i++) { getline(cin,help1); stringstream ss1(help1); ss1>>lei; while(ss1>>word) { for(int i = 0;i<word.size();i++) if(word[i]>='A'&&word[i]<='Z') word[i]+=32; m[word] = lei; } } while(getline(cin,help1)) { for(int i = 0;i<help1.size();i++) { if(help1[i]==','||help1[i]=='.'||help1[i]=='!'||help1[i]==';'||help1[i]=='?'||help1[i]=='('||help1[i]==')') help1[i] = ' '; } string s; stringstream ss2(help1); while(ss2>>s) { for(int i = 0;i<s.size();i++) { if(s[i]>='A'&&s[i]<='Z') s[i]+=32; } if(m.count(s)) { cout<<m[s]<<endl; break; } } }}
- 2017CSU暑假集训 Languages
- 2017CSU暑假集训二 G-River Hopscotch
- CSU-ACM2016暑假集训比赛2
- CSU-ACM2016暑假集训比赛1
- CSU-ACM2016暑假集训训练2-DFS
- CSU-ACM2016暑假集训比赛3
- CSU-ACM2016暑假集训比赛4
- CSU-ACM2016暑假集训比赛5
- CSU-ACM2016暑假集训比赛6
- CSU-ACM2016暑假集训比赛7
- CSU-ACM2016暑假集训比赛8
- CSU-ACM2016暑假集训比赛10
- CSU-ACM2016暑假集训比赛11
- CSU-ACM2017暑假集训比赛1 C
- CSU-ACM2017暑假集训比赛1 B
- CSU-ACM2017暑假集训比赛1 A
- CSU-ACM2017暑假集训比赛1 C
- CSU-ACM2017暑假集训比赛1 C
- Swift3.0中的Json对象和Json字符串
- PyQt5简易入门指南02,简单图片显示程序
- Step 2:Processing入门
- LeetCode(15)--4Sum
- 1126: 布尔矩阵的奇偶性
- 2017CSU暑假集训 Languages
- 架构师日记——Nginx简介
- linux 学习(1)
- POJ
- 结构体内不定长数组初始化,error: #1077: an initializer cannot be specified for a flexible array member
- 第一天
- flume监听端口整合kafka以及相关错误
- iPhone手机数据找回指南2:iPhone手机使用技巧
- UE4中实现截图功能并保存到指定路径