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 uestcmn at 2006-05-17 17:56:13 on Problem 1051
写了一个程序,按照他给的数据输出是正确的,但是提交上去后是wrong answer.
希望哪个牛人给组数据再测测.
以下是源程序:
#include<stdio.h>

char *letter1[26]={{".-"},{"-..."},{"-.-."},{"-.."},{"."},{"..-."},{"--."},

{"...."},{".."},
{".---"},{"-.-"},{".-.."},{"--"},{"-."},{"---"},{".--."},{"--.-"},{".-."},

{"..."},{"-"},
{"..-"},{"...-"},{".--"},{"-..-"},{"-.--"},{"--.."}};

char *letter2[4]={{"..--"},{"---."},{".-.-"},{"----"}};

struct maps
{
	int w;
	char s;
}map[30]={{1,'E'},{2,'T'},{11,'I'},{12,'A'},{21,'N'},{22,'M'},{111,'S'},

{112,'U'},{121,'R'},{122,'W'},
{211,'D'},{212,'K'},{221,'G'},{222,'O'},{1111,'H'},{1112,'V'},{1121,'F'},

{1122,'_'},{1211,'L'},{1212,','},
{1221,'P'},{1222,'J'},{2111,'B'},{2112,'X'},{2121,'C'},{2122,'Y'},{2211,'Z'},

{2212,'Q'},{2221,'.'},{2222,'?'}};

int numbers[100];
char code[410];

int convert(char *);
char search(int);

int main()
{
	int ks,i=0,j;
	char message[110],c;
	int codes,num,weight;
	
	scanf("%d",&ks);
	scanf("%c",&c);
	for(;ks>0;ks--)
	{
		i=0;
		j=0;
		gets(message);
		codes=convert(message);
		for(;codes>=0;codes--)
		{
			num=numbers[codes];
			weight=0;
			j=i+num;
			for(;i<j;i++)
			{
				c=code[i];
				switch(c)
				{
				case '.':
					weight=weight*10+1;
					break;
				case '-':
					weight=weight*10+2;
					break;
				default:
					break;
				}
			}

			c=search(weight);
			printf("%c",c);
		}

		printf("\n");
		message[0]='\0';
		code[0]='\0';
	}

	return 0;
}

int convert(char *s)
{
	int i=0,j=0;
    char c,*let,count=0;

	while((c=s[i])!=0)
	{
		if(c<='Z'&&c>='A')
			let=letter1[c-'A'];
		else
		{
			switch(c)
			{
			case '_':
				let=letter2[0];
				break;
			case '.':
				let=letter2[1];
				break;
			case ',':
				let=letter2[2];
				break;
			case '?':
				let=letter2[3];
				break;
			default:
				break;
			}
		}

		count=0;
		while(*let!=0)
		{
			code[j++]=*let++;
			count++;
		}
		numbers[i++]=count;
	}

	code[j]='\0';
	return i-1;
}

char search(int weight)
{
	int low=0,mid,high=30;

	mid=(high+low)/2;
	while(low<=high)
	{
		if(map[mid].w>weight)
			high=mid-1;
		else if(map[mid].w<weight)
			low=mid+1;
		else
			return(map[mid].s);

		mid=(low+high)/2;
	}

	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