2017湖南多校第一场-L(1011): Languages
来源:互联网 发布:java角色权限管理系统 编辑:程序博客网 时间:2024/04/29 15:07
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 dierent languages, the Enterprise team is trying to determine what type of beings
inhabited the planet.
Input
The rst line of input will be N (1 N 100), the number of dierent 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 specic language.
Keywords should be matched in a case-insensitive manner.
Output
For each line of sample text that follows the blank line separating the dened languages, print a
single line that identies the language with which the sample text is associated.
Sample Input Sample Output
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!
Vulcan
Romulan
解题思路:用map将单词映射为语言,使用stringstream,提高读入效率
使用字典树查询也可以~
#include<iostream>#include<cstdio>#include<string>#include<algorithm>#include<sstream>#include<map> using namespace std;int main(){ //ios::sync_with_stdio(false); //cin.tie(0); int T; cin>>T; string text,lan,word; map<string,string> m; getchar(); for(int i=0;i<T;i++) { getline(cin,text); stringstream ss1(text); ss1>>lan; while(ss1>>word) { for(int i=0;i<word.size();i++) { if(word[i]>='A'&&word[i]<='Z') word[i]+=32; } m[word]=lan; } } while(getline(cin,text)) { string x; for(int i=0; i<text.size(); i++) { if (text[i]==','||text[i]=='.'||text[i]=='!'||text[i]==';'||text[i]=='?'||text[i]=='('||text[i]==')') text[i]=' '; } stringstream ss2(text); while(ss2>>x) { for(int i=0; i<x.size(); i++) { if(x[i]>='A'&&x[i]<='Z') x[i]+=32; } if(m.count(x)) { cout << m[x] << endl; break; } } } return 0;}
- 2017湖南多校第一场-L(1011): Languages
- 2017湖南多校第一场-A(1001): Assignments
- 2017湖南多校第一场-F(1005): Federation Favorites
- 2017湖南多校第一场-Generations of Tribbles
- 2017湖南多校第一场-Enterprising Escape
- 2017湖南多校第二场-20170312
- 2017湖南多校第二场-20170312
- 2017湖南多校第二场-20170312
- 2017湖南多校第二场-20170312
- 2017湖南多校第三场
- 2017湖南多校第八场-20170429
- 2017湖南多校第一场-B(1002): Bones’s Battery
- 2016湖南多校训练第一场
- 湖南多校第八场
- 2017湖南多校第三场A(1025): Lawn mower
- 2017湖南多校第五场-A(1043): Biorhythms
- 2017湖南多校第五场 neerc 2013 解题报告
- 2145: 2017湖南多校第十三场-20170723
- C++迭代器iterator
- IntelliJ IDEA 2016破解码
- 105. Construct Binary Tree from Preorder and Inorder Traversal
- 浅析C++之指针和const限定符号
- js面向对象原型属性和实例属性
- 2017湖南多校第一场-L(1011): Languages
- TransferQueue
- GreenDao2 配置混淆错误解决
- windows server2012 IIS服务器上发布网站挖坑记
- Spring @Configuration 使用
- map用迭代器进行遍历的方法总结
- effect C++ 了解C++默默编写并调用哪些函数
- python3使用SQLAlchemy操作数据库
- GYM 100971 D.Laying Cables(set)