2017湖南多校第一场-L(1011): Languages
2017-03-22 16:31
239 查看
Languages
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 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湖南多校第一场-Generations of Tribbles
- 2017湖南多校第一场-Enterprising Escape
- 2017湖南多校第一场-B(1002): Bones’s Battery
- 2017湖南多校第一场-A(1001): Assignments
- 2017湖南多校第一场-F(1005): Federation Favorites
- hdu 6035:Colorful Tree (2017 多校第一场 1003) 【树形dp】
- 易互娱2017实习生招聘在线笔试第一场题目1 : 电子数字
- HDU 6040& 2017年多校训练第一场 1008题
- 2017多校2 1011 Regular polygon
- 2017杭电多校第七场1011 Kolakoski(签到题)HDU 6130
- 2017计蒜之道初赛第一场
- 2017 计蒜之道 初赛 第一场 阿里的新游戏(找规律,几何,模拟)
- 计蒜客 2017 初赛第一场 B. 阿里天池的新任务(简单)
- 计蒜客 2017 初赛第一场 B. 阿里天池的新任务(简单)
- [数论] 2017 计蒜之道 初赛 第一场 阿里天池的新任务
- [2017湖南集训7-9]大佬的问题 (数点问题)
- 2017湖南多校第十三场-COJ1963-Feed the rabbit
- 2017 多校训练第一场 KazaQ's Socks
- 牛客网——2017校招第一场编程题汇总
- 2017湖南多校第三场