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 |
贴代码Source Code Problem: 1051 User: oscar200101 Memory: 384K Time: 16MS Language: C++ Result: Accepted Source Code #include<iostream> #include<map> #include<string> #include<algorithm> using namespace std; map<char,string> a; string in[1001],pa[1001],nm[1001],out[1001]; int main() { /*呵呵*/ a.insert(pair<char,string>('A',".-"));a.insert(pair<char,string>('B',"-..."));a.insert(pair<char,string>('C',"-.-."));a.insert(pair<char,string>('D',"-.."));a.insert(pair<char,string>('E',"."));a.insert(pair<char,string>('F',"..-."));a.insert(pair<char,string>('G',"--."));a.insert(pair<char,string>('H',"...."));a.insert(pair<char,string>('I',".."));a.insert(pair<char,string>('J',".---"));a.insert(pair<char,string>('K',"-.-"));a.insert(pair<char,string>('L',".-.."));a.insert(pair<char,string>('M',"--"));a.insert(pair<char,string>('N',"-."));a.insert(pair<char,string>('O',"---"));a.insert(pair<char,string>('P',".--."));a.insert(pair<char,string>('Q',"--.-"));a.insert(pair<char,string>('R',".-."));a.insert(pair<char,string>('S',"..."));a.insert(pair<char,string>('T',"-"));a.insert(pair<char,string>('U',"..-"));a.insert(pair<char,string>('V',"...-"));a.insert(pair<char,string>('W',".--"));a.insert(pair<char,string>('X',"-..-"));a.insert(pair<char,string>('Y',"-.--"));a.insert(pair<char,string>('Z',"--.."));a.insert(pair<char,string>('_',"..--"));a.insert(pair<char,string>(',',".-.-"));a.insert(pair<char,string>('.',"---."));a.insert(pair<char,string>('?',"----")); int n; cin>>n; for(int k=1;k<=n;k++) { cin>>in[k]; for(int i=0;i<in[k].length();i++) { pa[k]+=a[in[k][i]]; nm[k]+=(a[in[k][i]]).length()+'0'; } reverse(nm[k].begin(),nm[k].end()); int tmp=0; for(int i=0;i<in[k].length();i++) { string t; t.reserve(4); for(int j=0;j<nm[k][i]-'0';j++)t+=pa[k][j+tmp]; tmp+=nm[k][i]-'0'; for(char i='A';i<='Z';i++) { if(a[i]==t) { out[k]+=i; break; } } if(a['_']==t)out[k]+='_'; if(a['?']==t)out[k]+='?'; if(a['.']==t)out[k]+='.'; if(a[',']==t)out[k]+=','; } } for(int k=1;k<=n;k++) { cout<<k<<": "; if(k!=n) cout<<out[k]<<endl; else cout<<out[k]; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator