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?用结构写了一个,超时,又重新写了一个,wa……可怜可怜, 帮帮忙吧】

Posted by leoyonn at 2005-03-27 17:41:39 on Problem 1002
  //////////////////////////////////
 //acm.1002..00448233.liuyang./////
//////////////////////////////////
#include <iostream.h>
#include <stdlib.h>
int nTens=1000000, nYes1, nYes2;
int compare(const void *a1 ,const void *a2);
void main(){
	int nLine;
	char cRead;
	char cTempdelete[2];
	cin >> nLine;
	int *nPhone = new int [nLine];
	int *nOfPhone = new int [nLine];
	cin.getline(cTempdelete,'\n');
	for(int i=0;i<nLine;i++){
		nTens=1000000;
		nOfPhone[i] = 1;
		nPhone[i] = 0;    
		while(1){
			cRead = cin.get();
			if(cRead == '\n')		break;
			else if(cRead == '-')	continue;
			else if(cRead >= 'A' && cRead <= 'P')	{nPhone[i] += nTens * ((cRead - 'A') / 3 + 2); nTens /= 10;}
			else if(cRead >= 'R' && cRead <= 'Y')	{nPhone[i] += nTens * ((cRead - 'A' - 1) / 3 + 2); nTens /= 10;}
			else if(cRead >= '0' && cRead <= '9')	{nPhone[i] += nTens * (cRead - '0'); nTens /= 10;}
		}
	}
	qsort((void *)nPhone, nLine, sizeof(nPhone[0]), compare);
	for(i = 0; i < nLine; i ++){
		if(nPhone[i] < 999999)continue;
		for(int j = i + 1; j < nLine; j ++){
			if(nPhone[j] < 999999)continue;
			if(nPhone[i] == nPhone[j]){
				nOfPhone[i] ++;
				nYes1 = 1;
				nPhone[j] = j;
				nYes2 = 1;
			}
		}
		if(nYes1 > 0)
			cout <<nPhone[i] / 1000000 <<nPhone[i] % 1000000 / 100000 <<nPhone[i] % 100000 / 10000 << "-"
				 << (nPhone[i] % 10000) / 1000 << (nPhone[i] % 1000) / 100
				 << (nPhone[i] % 100) / 10 << (nPhone[i] % 10) << " " <<nOfPhone[i] << endl;
		nOfPhone[i] = 1;
		nYes1 = 0;
	}
		if(nYes2 == 0)	cout <<"No duplicates." <<endl;
}
int compare(const void *a1 ,const void *a2){return *(int *)a1 -*(int *)a2;}

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