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. laravel更新某一个或几个字段

    //更新会员状态status $ary_where = array(); $ary_where[] = ['id', '=', $int_id]; $result = $this->obj_ad ...

  2. JavaScript事件冒泡与捕获

    event.preventDefault();    如果event.cancelable的值为true,可以取消默认事件 event.cancelable;             元素是否可以取消 ...

  3. 【SVN】centos环境下搭建SVN服务器

    1.安装SVN,有些linux发行版自带SVN,可以用下面方法检测是否安装SVN. svn --version 如果 Subversion 客户端没有安装,命令将报告svn命令找不到的错误. 我们可以 ...

  4. oracle建表,设置主键,修改属性等

    --建表 create table book( book_id number(10), book_name varchar2(20), book_price number(10,2), book_au ...

  5. sqlite3 的insert记录项思路

    sqlite3 的insert记录项思路 1.组合一个insert的sql语句 2.判断是否需要立即执行,若不是立刻执行的语句,则插入到待处理的链表中,供后续事务处理时提交.必须有一个专门线程来对事务 ...

  6. linux强制踢掉登录用户【转】

    [root@Wang ~]# w :: up :, users, load average: 0.71, 0.58, 0.57 USER TTY FROM LOGIN@ IDLE JCPU PCPU ...

  7. iframe 同域下父子页面的通信

    //共同引用的JS文件 common.js ; (function (window, $) { $(function ($) { window.trip = window.trip || {}; wi ...

  8. Team Foundation Server 2010服务器安装

    本安装指南使用Windows Server 2008企业版为基础,安装Windows Server 2008 SP2(必须),在此操作系统环境上进行TFS2010的安装与配置. 三.系统用户设置 1. ...

  9. 安装virtualenv(Scrapy)

    Windows 10家庭中文版,Python 3.6.4, virtualenv用来提供一个应用程序独立的 运行环境,这个独立是相对于系统的Python运行环境而言,开发者可以在virtualenv建 ...

  10. Python基础:内置异常(未完待续)

    本文根据Python 3.6.5的官文Built-in Exceptions编写,不会很详细,仅对Python的内置异常进行简单(重难点)介绍——很多异常都可以从名称判断出其意义,罗列所有的内置异常. ...