HDOJ1075字典翻译(map应用)
#include<iostream> #include<cstdio> #include<map> #include<string> #include<cstring> using namespace std; const int SIZE=10000+16; char book[SIZE]; map<string, string> dic; void fun_in() { char start[6]={'\0'}; scanf("%s",start); getchar(); string y; while(cin>>y&&y.compare("END")) { string x; cin>>x; dic[x]=y; } } bool letter(char a) { if('a'<=a&&a<='z') return true; return false; } void fun_out() { char start[6]={'\0'}; scanf("%s",start); getchar(); while(gets(book)&&strcmp(book,"END")!=0) { int r=0; while(book[r]) { char lett[SIZE]={'\0'}; int l=0; while(letter(book[r])&&book[r]) { lett[l++]=book[r++]; } string k=lett; if(dic.find(k)!=dic.end()) { cout<<dic[k]; } else { cout<<lett; } char fu[SIZE]={'\0'}; l=0; while(!letter(book[r])&&book[r]) { fu[l++]=book[r++]; } k=fu; if(dic.find(k)!=dic.end()) { cout<<dic[k]; } else { cout<<fu; } } printf("\n"); } } int main() { fun_in(); fun_out(); return 0; }
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步