zoj 3345 Language

zoj 3345 Language,第1张

zoj 3345 Language
#include <cstdio>#include <cstring>#include <cstdlib>#include <string>#include <algorithm>#include <map>#include <set>#include <cstring>#include <sstream>#include <iostream>#include <vector>using namespace std;const int N = 64;char language[N], catalog[N], word[N];map <string, int> catmap;map <string, int> lagmap;map <int, set <string> > Fword[8];const string Lan[8] = { "Chinese", "English", "Japanese", "German",};const char Fsten[][8][64] = { { {"[pn] shi [n]"}, {"[pn] [vi]"}, {"[pn] [vt] [n]"}, {"ni hao"}, }, { {"[pn] [vi]"}, {"[pn] [vt] [n]"}, {"There is a [n]"}, {"Happy new year"}, }, { {"[pn] ha [n] desu"}, {"[pn] ha [n] da"}, {"[pn] ha [n] ga [adj] desu"}, {"[n] saikou"}, {"yoi otoshiwo"}, }, { {"Ich habe ein [n]"}, {"Ich bin [n]"}, {"Ich heisse [n]"}, {"Du hast [n]"}, },};void init(){ for (int i = 0; i < 6; i++) Fword[i].clear(); catmap.clear(); lagmap.clear(); catmap["[n]"] = 0, catmap["[pn]"] = 1, catmap["[vi]"] = 2, catmap["[vt]"] = 3; catmap["[adj]"] = 4; lagmap["Chinese"] = 0, lagmap["English"] = 1, lagmap["Japanese"] = 2, lagmap["German"] = 3;}bool isok(int idx, string S, vector <string> & a){ istringstream iss(S); vector <string> b; string stmp; while (iss >> stmp) { b.push_back(stmp); } if (a.size() != b.size()) return false; for (int i = 0; i < (int) a.size(); i++) { if (b[i][0] == '[') { int idxtmp = catmap[b[i]]; if (Fword[idx][idxtmp].find(a[i]) == Fword[idx][idxtmp].end()) { return false; } } else { if (a[i] != b[i]) return false; } } return true;}char str[256];int main(){ int tcas, cas = 0; scanf("%d", &tcas); while (tcas--) { init(); printf("Case #%d:n", ++cas); int n, m; scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) { scanf("%s", language); scanf("%s", catalog); scanf("%s", word); Fword[lagmap[language]][catmap[catalog]].insert(word); } getchar(); for (int i = 0; i < m; i++) { gets(str); istringstream iss(str); vector <string> vstr; string stmp; while (iss >> stmp) { vstr.push_back(stmp); } int idx = -1; for (int i = 0; i < 4 && idx == -1; i++) { int num = 4; if (i == 2) num++; for (int j = 0; j < num && idx == -1; j++) { if (isok(i, Fsten[i][j], vstr)) { idx = i; break; } } } if (idx == -1) printf("I don't know.n"); else printf("%sn", Lan[idx].c_str()); } } return 0;}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4915401.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-12
下一篇 2022-11-12

发表评论

登录后才能评论

评论列表(0条)

保存