UVA 4995 —— Map的使用

来源:互联网 发布:python 类型判断 编辑:程序博客网 时间:2024/05/29 04:33

题目链接:http://livearchive.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2996

————————————————————————————————————————————

很水的题。可做map一个简单例子。

#include <stdio.h>#include <iostream>#include <string.h>#include <algorithm>#include <math.h>#include <string>#include <map>using namespace std;map<string,string>Map;int main(){    string s;    int k = 0;    Map["HELLO"] = "ENGLISH";    Map["HOLA"] = "SPANISH";    Map["HALLO"] = "GERMAN";    Map["BONJOUR"] = "FRENCH";    Map["CIAO"] = "ITALIAN";    Map["ZDRAVSTVUJTE"] = "RUSSIAN";    while(cin>>s)    {        if(s[0] == '#') break;        cout << "Case " << ++k <<": ";        if(Map.find(s) == Map.end())          cout <<  "UNKNOWN" << endl;        else          cout << Map[s] << endl;    }    return 0;}




原创粉丝点击