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 Callyou at 2004-03-02 09:34:37 on Problem 1002
//改了N次,WA了N次,本来在自己机器上跑不错啊!狂郁闷中...
#include <stdio.h>
#include <string.h>

struct Node
{
	char number[8];
	int times;
	Node * next;
};

void main()
{
	int nLine;
	Node * head = NULL, * current = NULL;
	scanf ( "%d", &nLine );
	for ( int i = 1; i <= nLine; i++ )
	{
		char buff [100] = {0}, result [8] = {0};
		scanf ( "%s", buff );
		for ( int j = 0, k = 0; buff [j] != 0; j++ )
		{
			if ( buff [j] >= '0' && buff [j] <= '9' )
			{
				result [k] = buff [j];
				k++;
			}
			else if ( buff [j] >= 'A' && buff [j] <= 'P' )
			{
				result [k] = (int) ( ( buff [j] - 'A' ) / 3 ) + '2';
				k++;
			}
			else if ( buff [j] >= 'R' && buff [j] <= 'Y' )
			{
				result [k] = (int) ( ( buff [j] - 'Q' ) / 3 ) + '7';
				k++;
			}
			result [7] = 0;
		}
		if ( head == NULL )
		{
			current = new Node;
			strcpy ( current -> number, result );
			current -> times = 1;
			current -> next = NULL;
			head = current;
		}
		else if ( strcmp ( head -> number, result ) > 0 )
		{
			current = new Node;
			strcpy ( current -> number, result );
			current -> times = 1;
			current -> next = head;
			head = current;
		}
		else if ( strcmp ( head -> number, result ) == 0 )
		{
			head -> times ++;
		}
		else
		{
			for ( current = head; current -> next != NULL; current = current -> next )
			{
				if ( strcmp ( current -> next -> number, result ) > 0 )
				{
					Node * temp = new Node;
					strcpy ( temp -> number, result );
					temp -> times = 1;
					temp -> next = current -> next;
					current -> next = temp;
					break;
				}
				else if ( strcmp ( current -> next -> number, result ) == 0 )
				{
					current -> next -> times ++;
					break;
				}
			}
			if ( current -> next == NULL )
			{
				Node * temp = new Node;
				strcpy ( temp -> number, result );
				temp -> times = 1;
				temp -> next = current -> next;
				current -> next = temp;
			}
		}
	}
	int flags = 0;
	for ( current = head; current != NULL; current = current -> next )
	{
		if ( current -> times > 1 )
		{
			flags = 1;
			for ( int k = 0; k < 3; k++ )
				printf ( "%c", current -> number [k] );
			printf ( "-" );
			for ( k = 3; k < 8; k++ )
				printf ( "%c", current -> number [k] );
			printf ( "%d\n", current -> times );
		}
	}
	if ( flags == 0 )
		printf ( "No duplicates.\n" );
}

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