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的更多相关文章

  1. uva 482 - Permutation Arrays

    <int, double> --> <int, string> 从而避免了输出格式: #include <vector> #include <strin ...

  2. 几道hash题

    1: UVa 10887 - Concatenation of Languages map 可以做 ,但是输入实在恶心,有空串之类的HASH模板: int Hash(char *s){   int s ...

  3. 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 语 ...

  4. 【水滴石穿】imooc_gp

    这个项目应该是一个标杆项目,看到之前很有几个项目都是按照这个项目的页面摆放顺序来的 不过可以作为自己做项目的一种方式 源码地址为:https://github.com/pgg-pgg/imooc_gp ...

  5. HDU 4329 MAP(stringstream的用法)

    这个题目有点绕,但是按着他的意思写不难模拟出来.本来是一场学弟们的训练赛,我这个学长在赛场上却WA了四次都没过,三条黑线就一直在我的脑袋上挂着... 赛后开始找原因,后来发现题目看错了,1/R中的R是 ...

  6. 利用map和stringstream数据流解题

    题目描述 喜闻乐见A+B.读入两个用英文表示的A和B,计算它们的和并输出. 输入 第一行输入一个字符串,表示数字A:第二行输入一个字符串表示数字B.A和B均为正整数. 输出 输出一个正整数n,表示A+ ...

  7. 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 ...

  8. Hex Dump In Many Programming Languages

    Hex Dump In Many Programming Languages See also: ArraySumInManyProgrammingLanguages, CounterInManyPr ...

  9. csuoj 1511: 残缺的棋盘

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1511 1511: 残缺的棋盘 时间限制: 1 Sec  内存限制: 128 MB 题目描述 输入 ...

随机推荐

  1. Backbone基础笔记

    之前做一个iPad的金融项目的时候有用到Backbone,不过当时去的时候项目已经进入UAT测试阶段了,就只是改了改Bug,对Backbone框架算不上深入了解,但要说我一点都不熟悉那倒也不是,我不太 ...

  2. Mongodb开启远程连接并认证

    环境: Mongodb版本:3.4.6 步骤: 1.  mongo创建管理员: 在mongo shell下: use admin db.createUser( { user: "testus ...

  3. 多年前写的DataTable与实体类的转换

    介绍 介绍 很多年前一直使用Ado.net,后来慢慢转型到其他的orm,在转型过程中,有意向将两者的模型结合起来,利用DataTable中的行状态完善一些mvc中的数据控制作用.现在把它放出来,留个纪 ...

  4. 【leetcode 简单】 第九十九题 字符串相加

    给定两个字符串形式的非负整数 num1 和num2 ,计算它们的和. 注意: num1 和num2 的长度都小于 5100. num1 和num2 都只包含数字 0-9. num1 和num2 都不包 ...

  5. java保存json格式数据,保存字符串和读取字符串

    1.java保存json格式数据,保存字符串和读取字符串 import java.io.*; class RWJson { public void wiite(String s, String toS ...

  6. C++ Primer 5th 第19章 特殊工具与技术

    C++是一种通用型语言,其设计者希望它能处理各种各样的问题,因此除了一些能适用于所有问题的语言特性,还有一些适用于特定问题的特性. 控制内存分配 某些程序对内存分配有着特殊的需求,它们不适合使用标准的 ...

  7. Multiple HTTPS Bindings IIS 7 Using appcmd

    http://toastergremlin.com/?p=308 Sometimes when using a wildcard SSL or Unified Communications Certi ...

  8. KDE下安装fcitx后终端不能输入中文

    编辑用户的  ~/.profile 文件(或/etc/profile): #fcitx export XIM_PROGRAM=fcitx export XIM=fcitx export GTK_IM_ ...

  9. socket相关系统调用的调用流程

    最近一直在读内核网络协议栈源码,这里以ipv4/tcp为例对socket相关系统调用的流程做一个简要整理,这些相关系统调用的内部细节虽然各有不同,但其调用流程则基本一致: 调用流程: (1)系统调用 ...

  10. 怎么看innodb的B+TREE层数?

    怎么看innodb的B+TREE层数?,下面以sysbench_testdata.sbtest2为例查看索引层数: - 查看相关系统 root@localhost [sysbench_testdata ...