CSUOJ 1826 Languages map+stringstream
Description
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 keywordsfound in various different languages, the Enterprise team is trying to determine what type of beingsinhabited the planet.
Input
The first line of input will be N (1 ≤ N ≤ 100), the number of different known languages. Thenext N lines contain, in order, the name of the language, followed by one or more words in thatlanguage, separated with spaces. Following that will be a blank line. After that will be a series oflines, 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, orhyphens, 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 sampletext will contain keywords from multiple languages. The sample text may contain additionalpunctuation (commas, periods, exclamation points, semicolons, question marks, and parentheses)and spaces, all of which serve as delimiters separating keywords. Sample text may contain wordsthat 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 asingle 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
Hint
又一次感受到C++ stl的强大
思路:使用 stringstream类读取字符串,通过>>操作分离出单词,然后进行判断
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<sstream>
#include<string>
#include<string.h>
#include<ctype.h>
#include<map>
using namespace std;
map<string, string>m;
void lower(string &s)
{
for (int i = 0; i < s.length(); i++)
{
s[i] = tolower(s[i]);
}
}
int main()
{
int T;
m.clear();
string a, b,name,s;
cin >> T;
getchar();
for (int i = 0; i < T; i++)
{
getline(cin, a);
stringstream ss(a);
ss >> name;
while (ss >> b)
{
lower(b);
m[b] = name;
}
}
while (getline(cin, s))
{
string tmp;
for (int i = 0; i < s.length(); i++)
{
if (s[i] == ',' || s[i] == '.' || s[i] == '!' || s[i] == ';' || s[i] == ' ? ' || s[i] == '(' || s[i] == ')')
s[i] = ' ';
}
stringstream ss1(s);
while (ss1 >> tmp)
{
lower(tmp);
if (m.count(tmp))
{
cout << m[tmp] << endl;
break;
}
}
}
return 0;
}
/**********************************************************************
Problem: 1826
User: leo6033
Language: C++
Result: AC
Time:68 ms
Memory:2348 kb
**********************************************************************/
CSUOJ 1826 Languages map+stringstream的更多相关文章
- uva 482 - Permutation Arrays
<int, double> --> <int, string> 从而避免了输出格式: #include <vector> #include <strin ...
- 几道hash题
1: UVa 10887 - Concatenation of Languages map 可以做 ,但是输入实在恶心,有空串之类的HASH模板: int Hash(char *s){ int s ...
- SWIG 3 中文手册——6. SWIG 和 C++
目录 6 SWIG 和 C++ 6.1 关于包装 C++ 6.2 方法 6.3 支持的 C++ 功能 6.4 命令行选项与编译 6.5.1 代理类的构造 6.5.2 代理类中的资源管理 6.5.3 语 ...
- 【水滴石穿】imooc_gp
这个项目应该是一个标杆项目,看到之前很有几个项目都是按照这个项目的页面摆放顺序来的 不过可以作为自己做项目的一种方式 源码地址为:https://github.com/pgg-pgg/imooc_gp ...
- HDU 4329 MAP(stringstream的用法)
这个题目有点绕,但是按着他的意思写不难模拟出来.本来是一场学弟们的训练赛,我这个学长在赛场上却WA了四次都没过,三条黑线就一直在我的脑袋上挂着... 赛后开始找原因,后来发现题目看错了,1/R中的R是 ...
- 利用map和stringstream数据流解题
题目描述 喜闻乐见A+B.读入两个用英文表示的A和B,计算它们的和并输出. 输入 第一行输入一个字符串,表示数字A:第二行输入一个字符串表示数字B.A和B均为正整数. 输出 输出一个正整数n,表示A+ ...
- C++ Style Languages: C++, Objective-C, Java, C#
Hyperpolyglot.org From Hyperpolyglot.org C++ Style Languages: C++, Objective-C, Java, C# a side-by-s ...
- Hex Dump In Many Programming Languages
Hex Dump In Many Programming Languages See also: ArraySumInManyProgrammingLanguages, CounterInManyPr ...
- csuoj 1511: 残缺的棋盘
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1511 1511: 残缺的棋盘 时间限制: 1 Sec 内存限制: 128 MB 题目描述 输入 ...
随机推荐
- 解决IE6中 PNG图片透明的终极方案-八种方案!
“珍惜生命,远离IE6”,IE6中的bug令很多Web前端开发人员实为头疼,因此不知道烧了多少脑细胞,在众多的Bug中最令人抓狂的就是IE对png图片的不支持,导致设计师和重构师放弃了很多很炫的效果, ...
- 【BZOJ】2208 [Jsoi2010]连通数
[题意]给定n个点的有向图,求可达点对数(互相可达算两对,含自身).n<=2000. [算法]强连通分量(tarjan)+拓扑排序+状态压缩(bitset) [题解]这题可以说非常经典了. 1. ...
- 如何在python的字符串中输入纯粹的{}
python的format函数通过{}来格式化字符串 >>> a='{0}'.format(123) >>> a ' 如果需要在文本中包含{}字符,这样使用就会报错 ...
- [SDOI2010]外星千足虫 题解 高斯消元+bitset简介
高斯消元 + bitset 简介: 高斯消元其实就是以加减消元为核心求唯一解.这道题还是比较裸的,可以快速判断出来.我们将每一只虫子看作一个未知数,这样根据它给出的 m 组方程我们可以高斯消元得出每一 ...
- c# 生成随机N位数字串(每位可以重复)
/// <summary> /// 生成随机数字窜 /// </summary> /// <param name="Digit">位数</ ...
- SQLServer 学习相关资料整理【转】
存储过程: SQL Server 存储过程 博客园上的一篇文章,讲解的非常详细,有测试代码,很实用. sqlserver存储过程中执行动态sql语句 The Curse and Blessings ...
- jq 监听input值的变化
$(".popWeiXing .name").bind("input propertychange", function() { modValue.diyDat ...
- 【CTF MISC】pyc文件反编译到Python源码-2017世安杯CTF writeup详解
1.题目 Create-By-SimpleLab 适合作为桌面的图片 首先是一张图片,然后用StegSolve进行分析,发现二维码 扫码得到一串字符 03F30D0A79CB0558630000000 ...
- KL散度(Kullback–Leibler divergence)
KL散度是度量两个分布之间差异的函数.在各种变分方法中,都有它的身影. 转自:https://zhuanlan.zhihu.com/p/22464760 一维高斯分布的KL散度 多维高斯分布的KL散度 ...
- Docker基础速成(一)
Docker基础速成(一) 给亲爱的写的docker基础速成,按照步骤操作,实践出真知,希望有提纲挈领之功效 1.docker简介 Docker 轻量级容器,如图,类似于一个个集装箱,把复杂或者零散的 ...