poj 2503 map容器



Babelfish
Time Limit: 3000MS
Memory Limit: 65536K
Total Submissions: 41268
Accepted: 17562

Description

You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have a dictionary to help you understand them.

Input

Input consists of up to 100,000 dictionary entries, followed by a blank line, followed by a message of up to 100,000 words. Each dictionary entry is a line containing an English word, followed by a space and a foreign language word. No foreign word appears more than once in the dictionary. The message is a sequence of words in the foreign language, one word on each line. Each word in the input is a sequence of at most 10 lowercase letters.

Output

Output is the message translated to English, one word per line. Foreign words not in the dictionary should be translated as "eh".

Sample Input

dog ogday
cat atcay
pig igpay
froot ootfray
loops oopslay

atcay
ittenkay
oopslay

Sample Output

cat
eh
loops



#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <cctype>
#include <queue>

using namespace std;

typedef long long LL;
const int inf = 0x3f3f3f3f;
const int N = 40005;

map<string, string>m; //定义一个map容器,由后者字符串代表m【string】的值, 比如m[string] = string;有键和值,first就是键,second就是值。 

int main()
{
    char x[N], y[N], c[N];
    char line[N];

    m.clear();//清空map容器, 还可以用 m.erase(m.begin(), m.end());
    while(1)
    {
       gets(line);

       if(line[0]=='\0')//输入是参考别人的,自己后来想了之前学过的stream输入,接下去会介绍;
        break;

       sscanf(line,"%s %s", x, y);

       m[y] = x;
    }

    while(~scanf("%s", c))
    {
        if(m[c] == "")
            printf("eh\n");
        else
            cout<<m[c]<<endl;
    }
    return 0;
}

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <cctype>
#include <queue>
#include <sstream>//头文件

using namespace std;

typedef long long LL;
const int inf = 0x3f3f3f3f;
const int N = 40005;

map<string, string>m;

int main()
{
    string line;
    char x[N], y[N];

    char c[N];

    stringstream s;

    m.clear();
    while(getline(cin, line))
    {
        if(line[0]=='\0')
            break;

        s<<line;

        s>>x;

        s>>y;

        s.clear();//不能忘了^_^

        m[y] = x;
    }

    while(~scanf("%s", c))
    {
        if(m[c] =="")
            printf("eh\n");
        else
            cout<<m[c]<<endl;
    }
    return 0;
}


按照上面的程序在编译器上跑一下, 自己可以试着输出中间的值。


这里举一个刚刚做的例子 poj 2503

Babelfish
Time Limit: 3000MS
Memory Limit: 65536K
Total Submissions: 41268
Accepted: 17562

Description

You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have a dictionary to help you understand them.

Input

Input consists of up to 100,000 dictionary entries, followed by a blank line, followed by a message of up to 100,000 words. Each dictionary entry is a line containing an English word, followed by a space and a foreign language word. No foreign word appears more than once in the dictionary. The message is a sequence of words in the foreign language, one word on each line. Each word in the input is a sequence of at most 10 lowercase letters.

Output

Output is the message translated to English, one word per line. Foreign words not in the dictionary should be translated as "eh".

Sample Input

dog ogday
cat atcay
pig igpay
froot ootfray
loops oopslay

atcay
ittenkay
oopslay

Sample Output

cat
eh
loops



#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <cctype>
#include <queue>

using namespace std;

typedef long long LL;
const int inf = 0x3f3f3f3f;
const int N = 40005;

map<string, string>m; //定义一个map容器,由后者字符串代表m【string】的值, 比如m[string] = string;有键和值,first就是键,second就是值。 

int main()
{
    char x[N], y[N], c[N];
    char line[N];

    m.clear();//清空map容器, 还可以用 m.erase(m.begin(), m.end());
    while(1)
    {
       gets(line);

       if(line[0]=='\0')//输入是参考别人的,自己后来想了之前学过的stream输入,接下去会介绍;
        break;

       sscanf(line,"%s %s", x, y);

       m[y] = x;
    }

    while(~scanf("%s", c))
    {
        if(m[c] == "")
            printf("eh\n");
        else
            cout<<m[c]<<endl;
    }
    return 0;
}

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <cctype>
#include <queue>
#include <sstream>//头文件

using namespace std;

typedef long long LL;
const int inf = 0x3f3f3f3f;
const int N = 40005;

map<string, string>m;

int main()
{
    string line;
    char x[N], y[N];

    char c[N];

    stringstream s;

    m.clear();
    while(getline(cin, line))
    {
        if(line[0]=='\0')
            break;

        s<<line;

        s>>x;

        s>>y;

        s.clear();//不能忘了^_^

        m[y] = x;
    }

    while(~scanf("%s", c))
    {
        if(m[c] =="")
            printf("eh\n");
        else
            cout<<m[c]<<endl;
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值