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

下面是我照着“标程”改写的,可就是LTE(超时)这是为什么呢???

Posted by xuguangshengqq at 2006-12-03 20:32:53 on Problem 1002
#include "stdafx.h"
#include<iostream.h>
#include<iomanip.h>      //参数化输入/输出
#include<stdlib.h>

int compare(const void * a,const void * b)
{
	return *((int*)a)-*((int*)b);
}

void main ()
{
	int i,j,k,num,cal,value=1;	cin>>num;
	char a[100],b[8];//存char串的数组,多申一个位置比较好
	//对于转化的问题,可以查表,比switch好
	const char con[]="22233344455566677778889999";//QZ不会被输入,所以这样一起处理没问题7777
	int * c=new int[num];//用动态内存分配不会浪费资源的,包括时间复杂度
	for(i=0;i<num;i++)
	{
		cin>>a;	k=0;
		for(j=0;a[j];j++)
		{
			if(a[j]>='A' && a[j]<='Z')
			{b[k]=con[a[j]-'A'];k++;continue;}
			if(a[j]>='0' && a[j]<='9')
			{b[k]=a[j];k++;}
		}
		//换成int进行排序//就算首位是零,这样也正确,因为首零,数字本来就小
		c[i]=atoi(b);//come from <stdlib.h>
	}
	
	qsort(c,num,sizeof(int),compare);//come from <stdlib.h>
	
	for(i=0;i<num;)
	{
		cal=1;
		for(j=i+1;j<num&&c[j]==c[i];j++)	cal++;//利用排好序的特点,把边算边输做到了极致
		if(cal>1)
		{
			value=0;
			cout<<setfill('0')<<setw(3)<<c[i]/10000<<"-"<<setfill('0')<<setw(4)<<c[i]%10000<<" "<<cal<<endl;//
		}//setw(int)  come from <iomanip.h>
		//setfill(char) come from <iomanip.h>
		//setfill的使用,很好的解决了首位为零的问题
		i=j;
	}
	if(value)	cout<<"No duplicates."<<endl;
	delete[]c;
}

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