CSU - 1826 Languages

Description

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

Hint

依然是STL的运用。在转换前记得把例句里的标点符号换成空格以便读取单词,以及转换大小写
sstream iostream string.h
getline(cin,s)读取一行到字符串
stringstream ss(s)字符串转换到字符串流
getline(ss,t,' ')从流读取到以' '结尾的字符串
注意cin 后getline 前面还多了一个空格
map
map<ElementType,ElementType> m;
map[a]=b;a到b的映射
m.count(a)判断是否存在该元素
原来还有这么好用的东西……省的写字典树
#include <stdio.h>
#include <iostream>
#include <map>
#include <string.h>
#include <sstream>
using namespace std;
map<string,string> m;
int main()
{
    string s;
    int n;
    cin>>n;
    while(n--){
        string t,lan;
        cin>>lan;
        getchar();
        //cout<<lan<<endl;
        getline(cin,s);
        int len = s.length();
        for(int i=0;i<len;i++){
            if(s[i]>='A'&&s[i]<='Z'){
                s[i]+=32;
            }
        }
        //cout<<s<<endl;
        stringstream ss(s);
        while(getline(ss,t,' ')){
            m[t]=lan;
        }
    }
    while(getline(cin,s)){
        int len = s.length();
        for(int i=0;i<len;i++){
            if(s[i]==','||s[i]=='.'||s[i]=='?'||s[i]=='!'||s[i]==';'||s[i]=='('||s[i]==')'){
                s[i]=' ';
            }
        }
        for(int i=0;i<len;i++){
            if(s[i]>='A'&&s[i]<='Z'){
                s[i]+=32;
            }
        }
        stringstream ss(s);
        string t;
        while(getline(ss,t,' ')){
            if(m.count(t)){
                cout<<m[t]<<endl;
                break;
            }
        }
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值