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 题目描述 输入 ...
随机推荐
- Xilinx Altera FPGA中的逻辑资源(Slices VS LE)比较
前言 经常有朋友会问我,“我这个方案是用A家的FPGA还是X家的FPGA呢?他们的容量够不够呢?他们的容量怎么比较呢?”当然,在大部分时候,我在给客户做设计的时候,直接会用到最高容量的产品,因为我们的 ...
- 20155325 2016-2017-2 《Java程序设计》第6周学习总结
教材学习内容总结 分类 输入流&输出流 字节流&字符流 节点流&处理流 核心方法 Input Stream int read(byte[]b,int off,int len) ...
- HDU 4707 Pet 邻接表实现
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4707 解题报告:题目大意是在无向图G中有n个点,分别从0 到n-1编号,然后在这些点之间有n-1条边, ...
- git之合并分支(git merge)------(三)
最近几天写小demo,总是自己拉取他人的代码,然后创建分支,在自己的分支上进行修改,然后提交到自己的分支,具体的这一步,我就不多讲了,因为在我的博客“工作中常用的Git操作”中有详细的介绍,今天主要讲 ...
- 49、多线程创建的三种方式之继承Thread类
继承Thread类创建线程 在java里面,开发者可以创建线程,这样在程序执行过程中,如果CPU空闲了,就会执行线程中的内容. 使用Thread创建线程的步骤: 1.自定义一个类,继承java.lan ...
- webpack详解
webpack是现代前端开发中最火的模块打包工具,只需要通过简单的配置,便可以完成模块的加载和打包.那它是怎么做到通过对一些插件的配置,便可以轻松实现对代码的构建呢? webpack的配置 const ...
- [转]CMake快速入门教程:实战
转自http://blog.csdn.net/ljt20061908/article/details/11736713 0. 前言 一个多月前,由于工程项目的需要,匆匆的学习了一下cmake的使 ...
- linux中set、unset、export、env、declare,readonly的区别以及用法
set命令显示当前shell的变量,包括当前用户的变量; env命令显示当前用户的变量; export命令显示当前导出成用户变量的shell变量. 每个shell有自己特有 ...
- 数论-求n以内的质数
一.埃拉托斯特尼筛法 名字很高大上,然而并没有什么卵用…… 思路: 在把<=√n的质数所有的<=n的倍数剔除,剩下的就都是质数了,很容易理解…… 复杂度O(nloglogn) #inclu ...
- cocos2dx中调用TinyXml读取xml配置文件 || cocos2d-x 中跨平台tinyxml读取xml文件方式
TiXmlDocument *doc = newTiXmlDocument; #if (CC_TARGET_PLATFORM ==CC_PLATFORM_ANDROID) //Android平台tin ...