CSU 1826:Languages(stringstream的应用)
来源:互联网 发布:关于网络暴力的演讲稿 编辑:程序博客网 时间:2024/06/10 05:03
Languages
Problem Description
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
题意:
现在有很多门语言,输入每行第一个单词是语言的名字,接下来一整行都是语言中的单词,每个单词只会出现在一种语言中(单词忽略大小写,并且逗号、感叹号、分号、时期、问号和括号不包含在单词内)。输入完以后,输入句子要我们判断是那种语言。
解题思路:
暴力。由于大小写,并且逗号、感叹号、分号、时期、问号和括号不包含在单词,我们直接把这些符号全部变成空格,大写全部转为小写,然后用stringstream来遍历单词,出现相同的单词就意味着找到这门语言(因为一个单词不会出现在两种语言)。
Code:
#include <iostream>#include <string>#include <sstream>using namespace std;string lgg[105];string name[105];int main(){ int n; cin>>n; for(int i=0; i<n; i++) { cin>>name[i]; getline(cin,lgg[i]); int len=lgg[i].length(); for(int j=0; j<len; j++) { if(lgg[i][j]==','||lgg[i][j]=='.'||lgg[i][j]=='!'||lgg[i][j]==':'||lgg[i][j]=='?'||lgg[i][j]==')'||lgg[i][j]=='(') lgg[i][j]=' '; else if(lgg[i][j]>='A'&&lgg[i][j]<='Z') lgg[i][j]+='a'-'A'; } } string s; while(getline(cin,s)) { int len=s.length(); for(int i=0;i<len;i++) { if(s[i]==','||s[i]=='.'||s[i]=='!'||s[i]==':'||s[i]=='?'||s[i]==')'||s[i]=='(') s[i]=' '; else if(s[i]>='A'&&s[i]<='Z') s[i]+='a'-'A'; } //for(string rr;ss1>>rr;cout<<rr<<endl); int flag=0; stringstream ss1(s); for(int i=0;i<n;i++) { string j; for(stringstream ss1(lgg[i]);ss1>>j;) { //cout<<j<<endl; string k; for(stringstream ss2(s);ss2>>k;) { //cout<<j<<' '<<k<<endl; if(j==k) { cout<<name[i]<<endl; flag=1; break; } } if(flag==1) break; } if(flag==1) break; } } return 0;}
- CSU 1826:Languages(stringstream的应用)
- CSU 1826 Languages map和stringstream
- Languages<stringstream的使用+map集合的使用>
- 2017CSU暑假集训 Languages
- ZCMU-1127-(stringstream的应用)
- (2012.03.24)Std::StringStream的小心应用
- 字符串流的应用(stringstream\ istringstream ostringstream)
- stringstream的用法(转)
- Languages CSU-ACM2017暑期训练1-Debug与STL
- Languages--CSU-ACM2017暑期训练1-Debug与STL
- uva 11549 Calculator Conundrum(Floyd 判圈法 和 stringstream的应用)
- 10815 - Andy's First Dictionary(set和stringstream的应用)
- stringstream的重要用法(数据类型转换)
- Languages
- csu 1446 Problem J Modified LCS (扩展欧几里得算法的简单应用)
- stringstream的用法
- stringstream的用法
- stringstream的用法
- 最短路径?青蛙(Frogger), ZOJ1942, POJ2253
- spring实现表单与服务器的数据交互
- 单播、广播、组播区别
- POJ
- Redis源码学习(1):adlist
- CSU 1826:Languages(stringstream的应用)
- 小明の魔法计划(最长倍数子序列)
- 怎样将SQL数据库里面的表导出
- 深入理解Java:SimpleDateFormat安全的时间格式化
- viewpager,fragment连用
- 美团点评2016研发题目-[编程题-美团] 奇数位丢弃
- 使用开源sweetalert出现Error:Execution failed for task ':app:processDebugManifest'.
- [论文笔记]Learning Deep Structured Semantic Models for Web Search using Clickthrough Data
- 单调栈模型--山峰