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 00448088 at 2005-03-23 22:54:46 on Problem 1002
#include<iostream.h>
#include<stdlib.h>
#include<iomanip.h>

long int iP[110000];

int compare(const void * a,const void * b);

int main()
{
	long int inNum;//定义输入数据组数
	cin>>inNum;

	long int i=0;//循环变量

	char input[300];//定义字符串,存放输入字符
	for(i=0;i<300;i++)
		input[i]='\0';

	for(i=0;i<inNum;i++)
	{
		cin>>input;//读入字符串

		//循环,将输入字符串转换成统一格式
		long int k=1000000;//变量用于数组下标的标记
		int n=0;
		iP[i]=0;

		for(int j=0;input[j]!='\0';j++)
		{
			if(input[j]>='A' && input[j]<='Q')
			{
				iP[i]+=((input[j]-'A')/3+2)*k;
				k/=10;
				n++;
			}
			else if(input[j]>'Q' && input[j]<='Z')
			{
				iP[i]+=((input[j]-'A'-1)/3+2)*k;
				k/=10;
				n++;
			}
			else if(input[j]<='9' && input[j]>='0')
			{
				iP[i]+=(input[j]-'0')*k;
				k/=10;
				n++;
			}
			if(n==7)
				break;
		}
	}

	//对输入字符串进行排序
	qsort((void *)iP,inNum,sizeof(iP[0]),compare);
	//for(i=0;i<inNum;i++)
	//	cout<<iP[i]<<endl;
	
	int state=0;//用于标记是否有相同电话号码
	long int count=0;
	long int j=0;
	
	for(i=0;i<inNum;)	
	{
		count=1;
		for(j=i+1; j<inNum && (iP[i]==iP[j]);j++)
			count++;
		if(count>1)
		{
			state=1;
			cout<<setfill('0')<<setw(3)<<iP[i]/10000<<"-"<<setw(4)<<iP[i]%10000<<" "<<count<<endl;
		}
		i=j;
	}
	
	//没有相同号码时输出
	if(state==0)
		cout<<"No duplicates."<<endl;

	return 0;
}

int compare(const void * a,const void * b)
{
	return (*(long int **)a-*(long int **)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