Languages--CSU-ACM2017暑期训练1-Debug与STL
来源:互联网 发布:nemo软件好用吗 编辑:程序博客网 时间:2024/06/13 22:39
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.
Input
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.
Output
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.
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
题目大意:给出几种语言,每种语言给几个关键词。 在一行文本中找到相应的关键词以确定语言。
坑点:用getline(cin,s)读一整行文本时,最先读入的是4之后的回车符,所以不在最前面加一个getline(cin,s),就会一直WA下去。有单独的空行时也要先用getline(cin,s)读了。
AC代码:
#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<vector>#include<cstdlib>#include<map>#include<sstream>using namespace std;string lg[109];map<string,int> mp;vector<string> keys[109];//long long store[109][300];int main(){ int n;cin>>n;// getchar(); string s; getline(cin,s); for(int i=1;i<=n;i++) { getline(cin,s); stringstream ss(s); string key; ss>>key;lg[i]=key; key.clear(); while(ss>>key) { for(int j=0;j<key.length();j++) key[j]=tolower(key[j]);// keys[i].push_back(key); mp[key]=i; key.clear(); } s.clear(); } getline(cin,s);s.clear(); while(getline(cin,s)) { for(int i=0;i<s.length();i++) { s[i]=tolower(s[i]); if(s[i]==','||s[i]=='.'||s[i]=='!'||s[i]==';'||s[i]=='?'||s[i]=='('||s[i]==')') s[i]=' '; } stringstream ss(s); string key; int flag=1; while(ss>>key) {// if(flag==0)break;// for(int i=1;i<=n;i++)// for(int j=0;j<keys[i].size();j++)// if(key==keys[i][j])// {// cout<<lg[i]<<endl;// flag=0;// break;// } if(mp.find(key)!=mp.end()) { cout<<lg[mp[key]]<<endl; break; } key.clear(); } s.clear(); }}
- Languages CSU-ACM2017暑期训练1-Debug与STL
- Languages--CSU-ACM2017暑期训练1-Debug与STL
- CSU-ACM2017暑期训练1-Debug与STL C-Languages-map判重
- CSU-ACM2017暑期训练1-Debug与STL hdu2736
- CSU-ACM2017暑期训练1-Debug与STL hdu1896-Stones
- CSU-ACM2017暑期训练1-Debug与STL -圆桌问题
- CSU-ACM2017暑期训练1-Debug与STL B
- CSU-ACM2017暑期训练1-Debug与STL A
- CSU-ACM2017暑期训练1-Debug与STL C
- CSU-ACM2017暑期训练1-Debug与STL E
- Train Problem I CSU-ACM2017暑期训练1-Debug与STL
- CSU-ACM2017暑期训练1-Debug与STL Jury Marks-set判重
- CSU-ACM2017暑期训练1-Debug与STL hdu1022-Train Problem I
- CSU-ACM2017暑期训练3-递推与递归 G
- CSU-ACM2017暑期训练3-递推与递归I
- CSU-ACM2017暑期训练3-递推与递归 J
- CSU-ACM2017暑期训练3-递推与递归 J
- CSU-ACM2017暑期训练3-递推与递归 H
- flowable 6.1.2 命令行完成请假审批流程的例子
- 1093. Count PAT's (25)
- UVA
- eclipse快捷键整理
- [BZOJ]4689: Find the Outlier 高斯消元
- Languages--CSU-ACM2017暑期训练1-Debug与STL
- UVA 548 Tree(中序+后序还原二叉树)
- HDOJ 6055-Regular polygon
- String,StringBuffer,StringBuilder 三者的讨论
- aop源码解析一:注册BPP
- ios底部输入框输入时被隐藏的bug解决
- 自己总结的html css知识点
- 2017多校第二场 HDU 6047 Maximum Sequence 线段树或者multiset维护区间最值
- 字符串替换