| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
高手指教!WA//改了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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator