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

贴个代码

Posted by qianguangpan at 2012-11-28 13:17:05 on Problem 1051
#include <iostream>
using namespace std;
char Alphabet[][5]={".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};
char Mark[][5]={"..--","---.",".-.-","----"};
int main(int argc, char* argv[])
{
	int n,i,j,k;
    char szMessage[101]={'\0'};
	char szCode[500]={'\0'};
	int nNumbers[101];
	int nNumberCount  = 0;
	char *pChar;
	char szTemp[5]={'\0'};
	cin>>n;
	for (i = 0;i<n;i++)
	{
		memset(szMessage,0,sizeof(szMessage));
		cin>>szMessage;
		cout<<i+1<<": ";
		memset(szCode,0,sizeof(szCode));
		pChar = szCode;
		nNumberCount = 0;
		int nCount=strlen(szMessage);
		for (j=0;j<nCount;j++)
		{
			nNumberCount ++;
			if (szMessage[j]>='A' && szMessage[j]<='Z')
			{
				nNumbers[j] = strlen(Alphabet[szMessage[j] - 'A']);
				strcat(szCode,Alphabet[szMessage[j]-'A']);
			}
			else
			{
				int nFlag;
				switch(szMessage[j])
				{
				default:break;
				case 95:nFlag = 0;break;
				case 46:nFlag = 1;break;
				case 44:nFlag = 2;break;
				case 63:nFlag = 3;break;
				}
				nNumbers[j] = strlen(Mark[nFlag]);
				strcat(szCode,Mark[nFlag]);
			}
		}
		for (j=0;j<nNumberCount;j++)
		{
			memset(szTemp,0,sizeof(szTemp));
			memcpy(szTemp,pChar,sizeof(char)*nNumbers[nNumberCount - j -1]);
			for (k=0;k<26;k++)
				if (strcmp(Alphabet[k],szTemp) == 0)
				  cout<<char(k+'A');
			for (k=0;k<4;k++)
				if (strcmp(Mark[k],szTemp) == 0)
				{
					switch(k)
					{
					default:break;
					case 0:cout<<"_";break;
					case 1:cout<<".";break;
					case 2:cout<<",";break;
					case 3:cout<<"?";break;
					}
				}
			pChar = pChar +nNumbers[nNumberCount - j -1];
		}
		cout<<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