Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

好长,是不是那26个一个一个敲得啊

Posted by TSERROF at 2012-11-03 14:17:19 on Problem 1051
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator