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

为什么我的程序在本机上运行完全正确,交上去就说WA.我第一次在这上面做题,没有什么经验,还请高手帮我看看

Posted by lstcJL at 2009-07-18 09:50:23 on Problem 1051
#include <stdlib.h>
#include <stdio.h>
#include "string.h"

void PrintResult(char midLetter[],char midNumber[],char record[30][5]);
char intToChar(int num);
int main()
{
	char midLetter[500];
	char midNumber[100];
	int a;
	char t,b[2];
	char record[30][5];
	int count;
	char array[500];
	int i=0;
	int j=0;
	
	strcpy(record[i++],".-");
	strcpy(record[i++],"-...");
	strcpy(record[i++],"-.-.");
	strcpy(record[i++],"-..");
	strcpy(record[i++],".");
	strcpy(record[i++],"..-.");
	strcpy(record[i++],"--.");
	strcpy(record[i++],"....");
	strcpy(record[i++],"..");
	strcpy(record[i++],".---");
	strcpy(record[i++],"-.-");
	strcpy(record[i++],".-..");
	strcpy(record[i++],"--");
	strcpy(record[i++],"-.");
	strcpy(record[i++],"---");
	strcpy(record[i++],".--.");
	strcpy(record[i++],"--.-");
	strcpy(record[i++],".-.");
	strcpy(record[i++],"...");
	strcpy(record[i++],"-");
	strcpy(record[i++],"..-");
	strcpy(record[i++],"...-");
	strcpy(record[i++],".--");
	strcpy(record[i++],"-..-");
	strcpy(record[i++],"-.--");
	strcpy(record[i++],"--..");
	strcpy(record[i++],".-.-");
	strcpy(record[i++],"..--");
	strcpy(record[i++],"---.");
	strcpy(record[i++],"----");
	scanf("%d",&count);
	b[1]='\0';
	for(i=0;i<count;i++)
	{
		fflush(stdin);
		gets(array);
		strcpy(midLetter,"");
		strcpy(midNumber,"");
		for(j=0;j<(int)strlen(array);j++)
		{
			t=array[j];
			if(t>='A'&& t<='Z')
			{
				a=t-'A';
				strcat(midLetter,record[a]);
				b[0]=intToChar(strlen(record[a]));
				strcat(midNumber,b);
			}
			else
			{
				switch(t)
				{
				case ',':
					strcat(midLetter,record[26]);
					b[0]=intToChar(strlen(record[26]));
					strcat(midNumber,b);
					break;
				case '_':
					strcat(midLetter,record[27]);
					b[0]=intToChar(strlen(record[27]));
					strcat(midNumber,b);
					break;
				case '.':
					strcat(midLetter,record[28]);
					b[0]=intToChar(strlen(record[28]));
					strcat(midNumber,b);
					break;
				case '?':
					strcat(midLetter,record[29]);
					b[0]=intToChar(strlen(record[29]));
					strcat(midNumber,b);
					break;
				default:
					break;
				}
			}	
		}
		printf("%d: ",i+1);
		PrintResult(midLetter,midNumber,record);
	}
	
	return 0;
}
	void PrintResult(char midLetter[],char midNumber[],char record[30][5])
	{
		char linshi[5];
		int k,i,j,c,d;
		k=0;
		for(i=strlen(midNumber)-1;i>=0;i--)
		{
			fflush(stdin);
			strcpy(linshi,"");
			j=(int)(midNumber[i])-48;
			for(d=0,c=0;d<j;d++,c++)
			{
				linshi[c]=midLetter[k+d];
			}
			linshi[j]='\0';
			k=k+j;
			for(j=0;j<30;j++)
			{
				if(strcmp(linshi,record[j])==0)
				{
					if(j<=25)
					{
						printf("%c",j+'A');
					}
					else
					{		
						if(strcmp(linshi,".-.-")==0)
							printf(",");
						else if(strcmp(linshi,"..--")==0)
							printf("_");
						else if(strcmp(linshi,"---.")==0)
							printf(".");
						else if(strcmp(linshi,"----")==0)
							printf("?");
					}
				}
			}
		}
		printf("\n");
	}
	char intToChar(int num)
	{
		return num+'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