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 0810311106 at 2009-09-02 13:14:05 on Problem 1051 and last updated at 2009-09-02 13:14:20
#include"stdio.h"
#include"string.h"
int main()
{
	int n,num=0;
	char map[300][10];
	strcpy(map['A'],".-");
	strcpy(map['B'],"-...");
	strcpy(map['C'],"-.-.");
	strcpy(map['D'],"-..");
	strcpy(map['E'],".");
	strcpy(map['F'],"..-.");
	strcpy(map['G'],"--.");
	strcpy(map['H'],"....");
	strcpy(map['I'],"..");
	strcpy(map['J'],".---");
	strcpy(map['K'],"-.-");
	strcpy(map['L'],".-..");
	strcpy(map['M'],"--");
	strcpy(map['N'],"-.");
	strcpy(map['O'],"---");
	strcpy(map['P'],".--.");
	strcpy(map['Q'],"--.-");
	strcpy(map['R'],".-.");
	strcpy(map['S'],"...");
	strcpy(map['T'],"-");
	strcpy(map['U'],"..-");
	strcpy(map['V'],"...-");
	strcpy(map['W'],".--");
	strcpy(map['X'],"-..-");
	strcpy(map['Y'],"-.--");
	strcpy(map['Z'],"--..");
	strcpy(map['?'],"----");
	strcpy(map['_'],"..--");
	strcpy(map[','],".-.-");
	strcpy(map['.'],"---.");
	
	scanf("%d",&n);
	getchar();
	while(n--)
	{
		char a[100],b[500],temp[6];
		int i,j,k,m,s;
		num++;
		scanf("%s",&a);
		strcpy(b,map[a[0]]);
		for(i=1;i<strlen(a);i++)
		  strcat(b,map[a[i]]);
		m=0;
		printf("%d: ",num);
		for(i=strlen(a)-1;i>=0;i--)
		{
			s=0;
			j=strlen(map[a[i]]);
			for(k=m;k<m+j;k++)
			temp[s++]=b[k];
			m+=j;
			temp[s]='\0';
			if(strcmp(temp,".-")==0)
			printf("A");
			else if(strcmp(temp,"-...")==0)
			printf("B");
			else if(strcmp(temp,"-.-.")==0)
			printf("C");
			else if(strcmp(temp,"-..")==0)
			printf("D");
			else if(strcmp(temp,".")==0)
			printf("E");
			else if(strcmp(temp,"..-.")==0)
			printf("F");
			else if(strcmp(temp,"--.")==0)
			printf("G");
			else if(strcmp(temp,"....")==0)
			printf("H");
			else if(strcmp(temp,"..")==0)
			printf("I");
			else if(strcmp(temp,".---")==0)
			printf("J");
			else if(strcmp(temp,"-.-")==0)
			printf("K");
			else if(strcmp(temp,".-..")==0)
			printf("L");
			else if(strcmp(temp,"--")==0)
			printf("M");
			else if(strcmp(temp,"-.")==0)
			printf("N");
			else if(strcmp(temp,"---")==0)
			printf("O");
			else if(strcmp(temp,".--.")==0)
			printf("P");
			else if(strcmp(temp,"--.-")==0)
			printf("Q");
			else if(strcmp(temp,".-.")==0)
			printf("R");
			else if(strcmp(temp,"...")==0)
			printf("S");
			else if(strcmp(temp,"-")==0)
			printf("T");
			else if(strcmp(temp,"..-")==0)
			printf("U");
			else if(strcmp(temp,"...-")==0)
			printf("V");
			else if(strcmp(temp,".--")==0)
			printf("W");
			else if(strcmp(temp,"-..-")==0)
			printf("X");
			else if(strcmp(temp,"-.--")==0)
			printf("Y");
			else if(strcmp(temp,"--..")==0)
			printf("Z");
			else if(strcmp(temp,"..--")==0)
			printf("_");
			else if(strcmp(temp,"---.")==0)
			printf(".");
			else if(strcmp(temp,".-.-")==0)
			printf(",");
			else if(strcmp(temp,"----")==0)
			printf("?");
		}	
		printf("\n");
	}
	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