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

1002:这个程序为什么会超时??

Posted by runningdog at 2006-07-26 18:11:32 on Problem 1002
#include<iostream>
#include<string>
using namespace std;
struct Ttelnum{
	string telnum;//号码
	int count;//重复计数
	bool isced;//计数和输出标计
};
int testcount;
Ttelnum *telnumset;
char direct[]={'2','2','2','3','3','3','4','4','4','5','5','5',
'6','6','6','7','7','7','8','8','8','9','9','9'};
int main()
{
	cin>>testcount;
	int numcount=testcount;
	telnumset=new Ttelnum[testcount];
	char ch;
	while(numcount>0)
	{//输入循环
		int w=testcount-numcount;
		int bitcount=7;
			int i=0;
		while(bitcount>0)
		{
			cin>>ch;
			if(ch=='-')continue;
			if(ch>='0'&&ch<='9')
				telnumset[w].telnum+=ch;
			if(ch>='A'&&ch<'Q')
				telnumset[w].telnum+=direct[ch-'A'];
			if(ch>'Q'&&ch<'Z')
				telnumset[w].telnum+=direct[ch-'A'-1];
			bitcount--;
		}
		telnumset[w].count=1;
		telnumset[w].isced=false;
		numcount--;
	}
	numcount=testcount;
	while(numcount>0)
	{//统计循环
		int q=testcount-numcount;
		for(int i=q+1;i<testcount;i++)
			if(!telnumset[i].isced&&telnumset[i].telnum==telnumset[q].telnum)
			{
				telnumset[i].isced=true;
				telnumset[q].count++;
			}
		numcount--;
	}
	
	string temp="9999999";
	int samecount=0;
	int y=-1;
	for(int k=0;k<testcount;k++)
	{//以下是输出循环
		temp="9999999";
		y=-1;
		for(int i=0;i<testcount;i++)
		    if(telnumset[i].isced==false
                         &&telnumset[i].telnum<temp&&telnumset[i].count>1)
			{
				y=i;
				temp=telnumset[i].telnum;
			}
		if(y==-1)break;
		telnumset[y].isced=true;
		for(int n=0;n<3;n++)
		{
			samecount++;
			cout<<telnumset[y].telnum[n];
		}
		cout<<'-';
		for(n=3;n<7;n++)
			cout<<telnumset[y].telnum[n];
		cout<<" "<<telnumset[y].count<<endl;
	}
	if(!samecount)cout<<"No duplicates."<<endl; 
	delete[] telnumset;
	//system("pause");
	return 0;
}

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