1051 P,MTHBGWB
2016-06-11 11:16
295 查看
用两个map存储加密和解密信息。
一个stack<int>存储字符长度,加密时长度入栈,解密时长度出栈,符合先进后出。
一个stack<int>存储字符长度,加密时长度入栈,解密时长度出栈,符合先进后出。
#pragma warning (disable : 4786) #include<iostream> #include<string> #include<map> #include<cstdio> #include<stack> using namespace std; map<char,string> morse; map<string,char> remorse; stack<int> num; void init(){ morse['A'] = ".-"; morse['B'] = "-..."; morse['C'] = "-.-."; morse['D'] = "-.."; morse['E'] = "."; morse['F'] = "..-."; morse['G'] = "--."; morse['H'] = "...."; morse['I'] = ".."; morse['J'] = ".---"; morse['K'] = "-.-"; morse['L'] = ".-.."; morse['M'] = "--"; morse['N'] = "-."; morse['O'] = "---"; morse['P'] = ".--."; morse['Q'] = "--.-"; morse['R'] = ".-."; morse['S'] = "..."; morse['T'] = "-"; morse['U'] = "..-"; morse['V'] = "...-"; morse['W'] = ".--"; morse['X'] = "-..-"; morse['Y'] = "-.--"; morse['Z'] = "--.."; morse['_'] = "..--"; morse['.'] = "---."; morse[','] = ".-.-"; morse['?'] = "----"; remorse[".-"] = 'A'; remorse["-..."] = 'B'; remorse["-.-."] = 'C'; remorse["-.."] = 'D'; remorse["."] = 'E'; remorse["..-."] = 'F'; remorse["--."] = 'G'; remorse["...."] = 'H'; remorse[".."] = 'I'; remorse[".---"] = 'J'; remorse["-.-"] = 'K'; remorse[".-.."] = 'L'; remorse["--"] = 'M'; remorse["-."] = 'N'; remorse["---"] = 'O'; remorse[".--."] = 'P'; remorse["--.-"] = 'Q'; remorse[".-."] = 'R'; remorse["..."] = 'S'; remorse["-"] = 'T'; remorse["..-"] = 'U'; remorse["...-"] = 'V'; remorse[".--"] = 'W'; remorse["-..-"] = 'X'; remorse["-.--"] = 'Y'; remorse["--.."] = 'Z'; remorse["..--"] = '_'; remorse["---."] = '.'; remorse[".-.-"] = ','; remorse["----"] = '?'; } int main(){ // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); init(); int N; cin>>N; for(int i=0;i<N;i++){ cout<<i+1<<": "; string input; cin>>input; string trans=""; num.empty(); for(int i=0;i<input.size();i++){ trans += morse[input.at(i)]; num.push(morse[input.at(i)].size()); } // cout<<trans<<endl; int index = 0; while(!num.empty()){ string output=""; // cout<<num.top(); int n = num.top(); while(n>0){ output += trans[index]; index++; n--; } // cout<<output; cout<<remorse[output]; num.pop(); } cout<<endl; } return 0; }
相关文章推荐
- 带参数文件上传
- this指针
- SHELL编程之特殊符号
- 多线程
- VMware Workstation :The VMware Authorization Service is not running.
- uploadify提示修改为中文
- 磨刀不误砍柴工,聊聊旧系统升级改造那些事儿
- GDI+(图像的显示和保存)
- js常用函数
- GSM LTE信号强度
- GDI+(画图工具的创建)
- GDI+(绘制图片背景文字)
- .net断点续传的原理
- 【MVC】会员注册/登录,普通验证,会员名是否注册Ajax验证以及会员邮件验证实现原理
- poj2186 popular cows
- 飞鸟集-20160611
- POJ 2955 Brackets
- 1050 To the Max
- 关于LayoutInflater.from(context).inflate()的使用的问题
- 一个 Linux 驱动的微波炉