传送门

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. jenkins忘记管理员登陆密码的补救措施

    jenkins可以作为我们日常运维过程中代码上线的发版平台,所以对jenkins的安全可靠的维护是十分重要的. 1)在登陆jenkins的时候,如果忘记普通用户的登陆密码,只要能用管理员账号登陆,还可 ...

  2. 运维工作中常用到的几个rsync同步命令

    作为一个运维工程师,经常可能会面对几十台.几百台甚至上千台服务器,除了批量操作外,环境同步.数据同步也是必不可少的技能.说到“同步”,不得不提的利器就是rsync. 下面结合本人近几年运维工作中对这一 ...

  3. Gitub

    1.下载地址(注册:jackchn,jackchn@foxmail.com) http://windows.github.com/ 2.使用 github for Windows使用介绍 搭建一个免费 ...

  4. Java反射机制的学习

    Java反射机制是Java语言被视为准动态语言的关键性质.Java反射机制的核心就是允许在运行时通过Java Reflection APIs来取得已知名字的class类的相关信息,动态地生成此类,并调 ...

  5. R 语言实现牛顿下降法

    凸是一个很好的性质.如果已经证明了某个问题是凸的,那这个问题基本上算是解决了. 最近在解决一个多目标优化的问题.多目标的问题往往是非凸的.好在能够知道这个问题的近似解大概是多少.这样这个多目标优化的问 ...

  6. C语言 预处理三(条件编译--#if)

    //#if 条件编译 //一般用于产品各个版本的语言包 #include<stdio.h> #include<stdlib.h> //#都是预处理指令,条件表达式必须在预处理里 ...

  7. php基础09:提取表单数据

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. 这些HTML、CSS知识点,面试和平时开发都需要 (转)

    http://www.cnblogs.com/w-wanglei/p/5414979.html No1.HTML 1.网页结构 网页结构一般都包含文档声明DOCTYPE,并且在head中的meta应该 ...

  9. LINUX SSH显示中文乱码

    ssh登陆后,执行: export LANG=zh_CN.gb2312就可以显示中文了.编辑/etc/sysconfig/i18n 将LANG="zh_CN.UTF-8" 改为 L ...

  10. C#本质论读书笔记:第一章 C#概述|第二章 数据类型

    第一章 1.字符串是不可变的:所有string类型的数据,都不可变,也可以说是不可修改的,不能修改变量最初引用的数据,只能对其重新赋值,让其指向内存中的一个新位置. 第二章 2.1 预定义类型或基本类 ...