传送门

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

Solution

注意Input加粗的部分,我在这里WA了一发。

这题的输入是个坑。首先考虑如何读取Keywords,这可归结为读入一行内的若干字符串

在本题中,一行输入可分为两部分:words(词), delimiters(定界符、分隔符)。

delimiters又分为两种:whitespace characters(空白字符), punctuations(标点)。

keywords部分的输入,delimiters不含puntuations。如果没有读入一行这个设定的话,

char s[];

scanf("%s", s);

就搞定了。加了这个限制,只要把每个word后面的delimiters也读入,看其中是否包含'\n'就好了:

char s[], delim[];

scanf("%s%[ \n]", s, delim);

这里有个地方要特别注意:

在Windows下换行符是'\n\r' (line feed + carriage return),此时按上面代码中的方式读取delimiters就不能读取/r,但Windows下的换行符并不总是'\n\r',也有只是'\n'的情况,可能跟文件的扩展名有关吧,这个问题我暂不清楚。我调试时是从无扩展名的文本文件in读入的,换行符是'\n',不知换成in.txt会如何。但无论如何

char s[], delim[];

scanf("%s%[ \n\r]", s, delim);

都能正确处理。

-------------------------------------------------------------------------------------------------------------

sample text的输入要多考虑punctuations,可如此处理:

char s[], delim[];

scanf("%*[,.!;() \n]"), scanf("%[^,.!;() \n]%[,.!;() \n]", s, delim);

这样写其实有点多余,下面Implementation里的第二份代码给出了另一种做法。

注意这里如果写成

char s[], delim[];

scanf("%*[,.!;() \n]%[^,.!;() \n]%[,.!;() \n]", s, delim);

就错了。(请考虑函数scanf()在什么情况下return)

Implementation

#include <bits/stdc++.h>
using namespace std;
const int N();
map<string, int> mp;
char lang[N][], s[], delim[];
string t; int main(){
int n;
scanf("%d", &n);
for(int i=; i<n; i++){
scanf("%s", lang[i]);
for(bool flag=false; !flag;){
scanf("%s%[ \n]", s, delim);
for(int i=; s[i]; i++)
s[i]=tolower(s[i]);
t=s;
mp[t]=i;
for(int i=; delim[i]; i++)
if(delim[i]=='\n'){
flag=true;
break;
}
}
} for(bool flag=false; scanf("%*[,.!;() \n]"), ~scanf("%[^,.!;() \n]%[,.!;() \n]", s, delim); ){
if(!flag){
for(int i=; s[i]; i++)
s[i]=tolower(s[i]);
t=s;
if(mp.find(t)!=mp.end()){
flag=true;
puts(lang[mp[t]]);
}
}
for(int i=; delim[i]; i++)
if(delim[i]=='\n'){
flag=false;
break;
}
}
}
#include <bits/stdc++.h>
using namespace std;
const int N();
map<string, int> mp;
char lang[N][], s[], delim[];
string t; int main(){
int n;
scanf("%d", &n);
for(int i=; i<n; i++){
scanf("%s", lang[i]);
for(bool flag=false; !flag;){
scanf("%s%[ \n]", s, delim);
for(int i=; s[i]; i++)
s[i]=tolower(s[i]);
t=s;
mp[t]=i;
for(int i=; delim[i]; i++)
if(delim[i]=='\n'){
flag=true;
break;
}
}
}
scanf("%*[,.!;() \n]");
for(bool flag=false; ~scanf("%[^,.!;() \n]%[,.!;() \n]", s, delim); ){
if(!flag){
for(int i=; s[i]; i++)
s[i]=tolower(s[i]);
t=s;
if(mp.find(t)!=mp.end()){
flag=true;
puts(lang[mp[t]]);
}
}
for(int i=; delim[i]; i++)
if(delim[i]=='\n'){
flag=false;
break;
}
}
}

UVALive 6523 Languages的更多相关文章

  1. UVALive - 4108 SKYLINE[线段树]

    UVALive - 4108 SKYLINE Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug ...

  2. UVALive - 3942 Remember the Word[树状数组]

    UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...

  3. UVALive - 3942 Remember the Word[Trie DP]

    UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...

  4. PLoP(Pattern Languages of Programs,程序设计的模式语言)

    2014/8/1 12:24:21潘加宇 http://www.umlchina.com/News/Content/340.htmPloP大会2014即将举行 PLoP(Pattern Languag ...

  5. Natural language style method declaration and usages in programming languages

    More descriptive way to declare and use a method in programming languages At present, in most progra ...

  6. ECSHOP \admin\edit_languages.php GETSHELL Based On Injection PHP Code Into /languages/zh_cn/user.php

    目录 . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述 对于很多CMS网站来说,它们都需要保存很多的网站META信息,最常用的最佳实践是以 ...

  7. 思维 UVALive 3708 Graveyard

    题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...

  8. Scripting Languages

    Computer Science An Overview _J. Glenn Brookshear _11th Edition A subset of the imperative programmi ...

  9. UVALive 6145 Version Controlled IDE(可持久化treap、rope)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

随机推荐

  1. [应用层]mail邮件协议

    转:http://***/chapter-14/ 以前老记不住这smtp和pop3谁收谁发. 简单邮件传输协议(SMTP),用来发送或中转发出的电子邮件,占用tcp 25端口. 第三版邮局协议(POP ...

  2. C语言 百炼成钢16

    //题目46:海滩上有一堆桃子,五只猴子来分.第一只猴子把这堆桃子凭据分为五份,多了一个,这只 //猴子把多的一个扔入海中,拿走了一份.第二只猴子把剩下的桃子又平均分成五份,又多了 //一个,它同样把 ...

  3. C#泛型委托,匿名方法,匿名类

    class Test { delegate K proxy<T, K>(T t, K k); //泛型委托,注意返回值的写法,返回值的类型K先于其声明proxy<T,K>中的K ...

  4. C# 杂项

    1,函数访问等级必须高于参数等级,如函数等级是PUBLIC,则参数必须高于等于PUBLIC,若为INTERNAL 则不行.INTERNAL 低于PUBLIC, 用于同一个程序集内引用,PUBLIC则可 ...

  5. JS案例之7——瀑布流布局(2)

    这个例子与上一篇类似,唯一的区别是排序的方式有差别.上一篇是在高度最小的列里插入内容,这个案例是按顺序放置内容. 两种方法各有优缺点.第一种需要在图片内容加载完成的情况下有效.这个例子不需要在wind ...

  6. ant命令总结

    ant命令总结 博客分类: 版本管理 svn , maven , ant   ant命令总结 1 Ant是什么?  Apache Ant 是一个基于 Java的生成工具. 生成工具在软件开发中用来将源 ...

  7. 北京联想招聘-java 云服务开发工程师 加入qq 群:220486180 或者直接在此 留言咨询

     Position Title: 云服务开发工程师 Experience Required:  3 - 5 Years 负责联想企业网盘服务端开发  Position Requirements  1. ...

  8. LINUX信息安全系统设计基础第二周学习总结

    1 Linux命令 2 man命令 1.Terminal(终端) Linux 系统还提供了一个叫做终端模拟器的程序(Terminal),下面几个比较常见的终端模拟器,例如 gnome-terminal ...

  9. silverlight ListBox 多列图片效果

    这个功能之前用wpf写过一次这次用Silverlight写一次 这两种写法上基本上没有太大的差别 这个Demo并不完美,只是给大家提供一个思路 源码:SilverLightListPricture.r ...

  10. WP&Win10开发: RichTextBlock实现富文本并处理换行

    思路:1.构建字典.2.在字符串中匹配字典的key,将匹配到的key转换成对应的value3.将替换后的字符串,转化成xaml形式,加载该xaml以实现富文本. 代码如下: private Parag ...