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 TearfulSword at 2005-04-24 18:09:09 on Problem 1002
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

void normalize(char* telnum,char* stdtelnum,int len);
int sort_function( const void *a, const void *b); 

char telnum[100000][100];
char stdtelnum[100000][10];

int main(){
	int n;//number of input
	int i,m=0,k=0;
	
	cin >> n;
	getchar();
	for (i = 0;i < n;i++)
	{
		fgets(telnum[i],30,stdin);
		normalize(telnum[i],stdtelnum[i],strlen(telnum[i]));
	}
	qsort(stdtelnum,n,10,sort_function);
	
	for (i = 0;i < n;i++)
	{
		if (i == 0 || strcmp(stdtelnum[i],stdtelnum[i-1]) == 0)
			m++;
		else if(i == n-1 || strcmp(stdtelnum[i],stdtelnum[i-1]) != 0)
		{
			if (m != 1) {
				cout << stdtelnum[i-1] << " " << m << endl;
				k ++;
			}
			m = 1;
		}
	}
	if (k == 0) 
		cout << "No duplicates.";
	return 0;

}
	
void normalize(char *telnum,char *stdtelnum,int len)
{
	int i;
	int stdcount;
	for (i = 0,stdcount = 0; i < len && stdcount < 8;i++)
	{
		if (stdcount == 3)
		{
			stdtelnum[stdcount] = '-';
			stdcount++;
			i--;
			continue;
		}
		switch(telnum[i])
		{
		case '1':case '2':case '3':case '4':case '5':
		case '6':case '7':case '8':case '9':case '0':
			stdtelnum[stdcount] = telnum[i];
			stdcount++;
			break;
		case 'A':case 'B':case 'C':
			stdtelnum[stdcount] = '2';
			stdcount++;
			break;
		case 'D':case 'E':case 'F':
			stdtelnum[stdcount] = '3';
			stdcount++;
			break;
		case 'G':case 'H':case 'I':
			stdtelnum[stdcount] = '4';
			stdcount++;
			break;
		case 'J':case 'K':case 'L':
			stdtelnum[stdcount] = '5';
			stdcount++;
			break;
		case 'M':case 'N':case 'O':
			stdtelnum[stdcount] = '6';
			stdcount++;
			break;
		case 'P':case 'R':case 'S':
			stdtelnum[stdcount] = '7';
			stdcount++;
			break;
		case 'T':case 'U':case 'V':
			stdtelnum[stdcount] = '8';
			stdcount++;
			break;
		case 'W':case 'X':case 'Y':
			stdtelnum[stdcount] = '9';
			stdcount++;
			break;
		}
	}
	stdtelnum[8] = '\0';
}

int sort_function( const void *a, const void *b) 
{ 
   return( strcmp((char*)a,(char*)b) ); 
} 

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