POJ 2503 Babelfish map水過,字典樹????

map用法:

map<string,string>q;

可以直接q[s1]  = s2; 這開闢了一個空間。

查找可以s.find(s1); 返回一個迭代器,指向s1 可以 ,   printf("%s\n", q[s1].c_str()); 輸出string,如果是%d,則 q[s1]即可

也可以s.count(s1),統計s1數量,只能是1||0,

s.erase(s1),刪除s1

s.clear();全部清空

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>

using namespace std;

int main()
{
    map<string,string>q;
    map<string,string> :: iterator t;
    char s[15], s1[15], s2[15];

    while(gets(s)&&strlen(s)){
        sscanf(s,"%s %s", s1, s2);
        q[s2] = s1;
    }
    while(~scanf("%s", s1)){
        t = q.find(s1);
        if(t != q.end()){
            printf("%s\n", q[s1].c_str());//cout << t->second << endl;
        }else {
            printf("eh\n");
        }
    }

    return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章