Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
好长,是不是那26个一个一个敲得啊#include<iostream> #include <string> #include<map> using namespace std; int main() { map<char,string>decode1; map<string,char>decode2; decode1['A']=".-"; decode1['B']="-..."; decode1['C']="-.-."; decode1['D']="-.."; decode1['E']="."; decode1['F']="..-."; decode1['G']="--."; decode1['H']="...."; decode1['I']=".."; decode1['J']=".---"; decode1['K']="-.-"; decode1['L']=".-.."; decode1['M']="--"; decode1['N']="-."; decode1['O']="---"; decode1['P']=".--."; decode1['Q']="--.-"; decode1['R']=".-."; decode1['S']="..."; decode1['T']="-"; decode1['U']="..-"; decode1['V']="...-"; decode1['W']=".--"; decode1['X']="-..-"; decode1['Y']="-.--"; decode1['Z']="--.."; decode2[".-"]='A'; decode2["-..."]='B'; decode2["-.-."]='C'; decode2["-.."]='D'; decode2["."]='E'; decode2["..-."]='F'; decode2["--."]='G'; decode2["...."]='H'; decode2[".."]='I'; decode2[".---"]='J'; decode2["-.-"]='K'; decode2[".-.."]='L'; decode2["--"]='M'; decode2["-."]='N'; decode2["---"]='O'; decode2[".--."]='P'; decode2["--.-"]='Q'; decode2[".-."]='R'; decode2["..."]='S'; decode2["-"]='T'; decode2["..-"]='U'; decode2["...-"]='V'; decode2[".--"]='W'; decode2["-..-"]='X'; decode2["-.--"]='Y'; decode2["--.."]='Z'; decode2["..--"]='_'; decode2[".-.-"]=','; decode2["---."]='.'; decode2["----"]='?'; int T; cin>>T; for(int i=1;i<=T;++i) { string code,s,ans; int number[100]={0}; cin>>s; int cnt=0,count=0; for(int j=0;j<s.size();++j) { if(s[j]=='_'){ code+="..--";number[cnt++]=4;continue;} else if(s[j]==','){ code+=".-.-";number[cnt++]=4;continue;} else if(s[j]=='.'){ code+="---.";number[cnt++]=4;continue;} else if(s[j]=='?'){ code+="----";number[cnt++]=4;continue;} else { code.append(decode1[s[j]]); number[cnt++]=decode1[s[j]].size(); } } for(int j=cnt-1;j>=0;--j) { string t=code.substr(count,number[j]); count+=number[j]; ans+=decode2[t]; } cout<<i<<": "<<ans<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator