POJ 2503 Babelfish map水過,字典樹????
阿新 • • 發佈:2019-02-18
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; }