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

服了它了,测试数据是什么啊?凡是能想到的数据都能过,老是wrong answer!!!贴出代码给大伙看看

Posted by bobcoc at 2009-11-27 23:00:32 on Problem 1002
#include<iostream>
#include <string.h>
using namespace std;
char mymap['Z'-'0'];
int mynumber[100000];
int mycount[100000];
int nlenth=-1;
int myfind(int x)
{
	if (nlenth<0)//列表为空时返回-1
	return -1;
	int l=0,r=nlenth;
	int p;
	p=(l+r)/2;
	while(l<=r)
	{
		if (x==mynumber[p])
			break;
		
		if(x<mynumber[p])
			r=p-1;
		if(x>mynumber[p])
			l=p+1;
		p=(l+r)/2;
	}
	if(l<=r)
		return p;
	else 
		return -1;
}
void myinsert(int x)
{
	int p=nlenth;
	while(x<mynumber[p])
	{
		mynumber[p+1]=mynumber[p];
		mycount[p+1]=mycount[p];
		p--;
	}
	mynumber[p+1]=x;
	mycount[p+1]=1;
	nlenth++;

}
int main()
{
	for(char i='0';i<='9';i++)
		mymap[i-'0']=i-'0';
	for(char i='A';i<'Z';i++)
	{
		if(i<'Q')
			mymap[i-'0']=(i-'A')/3+2;
		if(i>'Q')
			mymap[i-'0']=(i-'Q')/3+7;
	}
	int n;
	cin>>n;
	char c[50],*p;
	int t,nx;
	for(int i=0;i<n;i++)
	{
		cin>>c;
		p=c;
		nx=0;

		while(*p)//鍙栧嚭鐢佃瘽鍙风爜骞跺皢瀹冭浆鎹负涓€涓暣鏁?鍙嶈浆瀛樻斁)
		{
			if(*p!='-')
			{
				t=mymap[*p-'0'];
				nx=nx*10+t;
			}
			p++;				
		}
		t=myfind(nx);//鍘绘暟缁勯噷闈㈡煡鎵緉x
	if(t==-1)//鏈壘鍒板垯鎻掑叆鍒版暟缁勯噷锛屽苟璁剧疆瀹冪殑涓暟涓?
		{
			myinsert(nx);
		}
		else
		{
			mycount[t]++;//鎵惧埌鏃跺彧瑕佸皢瀹冪殑涓暟鍔?
		}
	}
	n=0;
	bool haveduplicates=false;
	while(mycount[n])
	{
		if (mycount[n]>1)
		{	
			int tt=mynumber[n];
			haveduplicates=true;
			int power=1000000;
			for(int j=0;j<3;j++)
			{
				t=tt/power;
				cout<<t;
				tt-=t*power;
				power/=10;
			}
			cout<<"-";
			for(int j=0;j<4;j++)
			{
				t=tt/power;
				cout<<t;
				tt-=t*power;
				power/=10;
			}
			cout<<" "<<mycount[n]<<endl;
		}
		

		n++;
	}
	if (!haveduplicates)
	{
		cout<<"No duplicates."<<endl;
	}
	


	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