ZOJ 1068 P,MTHBGWB
2017-04-20 07:06
232 查看
查看原题
题意
摩斯电码表已知,给出一串字符,隐含了它转换的摩斯电码和切割长度顺序。问同一行摩斯电码按倒置后的切割长度顺序进行切割,能得到什么字符串。思路
数组代码
#include <iostream> #include <stdio.h> #include <string.h> #include <string> using namespace std; int main(){ int n;cin>>n; string Morse[30]={".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--..","..--",".-.-","---.","----"}; for(int casenum=1;casenum<=n;casenum++){ int order[101]; string morse=""; string message; cin>>message; for(int i=0;i<message.size();i++){ if(message[i]=='_'||message[i]==','||message[i]=='.'||message[i]=='?'){ switch (message[i]){ case '_':order[i]=4;morse+="..--"; break; case ',':order[i]=4;morse+=".-.-"; break; case '.':order[i]=4;morse+="---."; break; case '?':order[i]=4;morse+="----"; break; } } else{ order[i]=Morse[message[i]-'A'].length(); morse+=Morse[message[i]-'A']; } } int step=0; cout<<casenum<<": "; for(int i=message.size()-1;i>=0;i--){ string temp=""; for(int j=0;j<order[i];j++){ temp+=morse[step]; step++; } for(int k=0;k<30;k++){ if(Morse[k]==temp){ if(k<26){ printf("%c",'A'+k); } else{ switch(k){ case 26:cout<<'_'; break; case 27:cout<<','; break; case 28:cout<<'.'; break; case 29:cout<<'?'; break; } } } } } cout<<endl; } return 0; }
相关文章推荐
- ZOJ1068 P,MTHBGWB
- ZOJ 1068 P,MTHBGWB
- ZOJ 1068 P,MTHBGWB
- 1068:P,MTHBGWB
- zoj1068P,MTHBGWB
- 1068 P,MTHBGWB
- fjnu 1074 P,MTHBGWB
- 北大poj Q3 P,MTHBGWB
- poj 1051 P,MTHBGWB(字符串,较麻烦)
- POJ 1051 P,MTHBGWB
- POJ 1051 P,MTHBGWB 简单字符串转换
- 基础题训练(简单数学题、字符串)P,MTHBGWB POJ-1051
- 1051 P,MTHBGWB
- POJ 1051 P,MTHBGWB
- P,MTHBGWB
- POJ-1051-P,MTHBGWB
- P,MTHBGWB 水题
- POJ 1051: P,MTHBGWB
- poj 1051 P,MTHBGWB
- zoj1068 P,MTHBGWB