【題解】ZeroJudge a135: 12250 – Language Detection

【題目敘述】https://zerojudge.tw/ShowProblem?problemid=a135
Virtual Judge: https://vjudge.net/problem/UVA-12250

#include <iostream>
#include <map>
using namespace std;

int main() {
    map <string, string> mp;
    mp["HELLO"] = "ENGLISH";
    mp["HOLA"] = "SPANISH";
    mp["HALLO"] = "GERMAN";
    mp["BONJOUR"] = "FRENCH";
    mp["CIAO"] = "ITALIAN";
    mp["ZDRAVSTVUJTE"] = "RUSSIAN";
    string s;
    int count = 0;
    while (cin >> s){
        if (s == "#") break;
        count++;
        cout << "Case " << count << ": ";
        if (mp.count(s)) cout << mp[s] << endl;
        else cout << "UNKNOWN" << endl;
    }
}

Python code (credit: Amy Chou)

dic = {
       "HELLO": "ENGLISH",
       "HOLA": "SPANISH",
       "HALLO": "GERMAN",
       "BONJOUR": "FRENCH",
       "CIAO": "ITALIAN",
       "ZDRAVSTVUJTE": "RUSSIAN",
       }

TC = 1
while True:
    s = input()
    if s == "#":
        break
    
    print(f"Case {TC}: ", end="")
    TC += 1
    if s in dic.keys():
        print(dic[s])
    else:
        print("UNKNOWN")
分享本文 Share with friends