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

恳求哪位哥们指点迷津。不知道这个程序怎么还是错误的!

Posted by Odeur at 2006-08-19 22:38:16
#include<algorithm>
#include<iostream>
#include<string>
using namespace std;
#define N 1000001
int res[N];
extern pos=0;
bool cmp(int x,int y)
{
	return(x<y);
}
//////////////tr()
void  tr(char a[])
{
	char ch;
	int j=0;
	ch=a[0];
	int temp=0;
	int resA=0;
	while(ch)
		{
			switch(ch)
			{
				case 'A':
				case 'B':
				case '2':
				case 'C':temp=2;break;
				case 'D':
				case 'E':
				case '3':
				case 'F':temp=3;break;
				case 'G':
				case 'H':
				case '4':
				case 'I':temp=4;break;
				case 'J':
				case 'K':
				case '5':
				case 'L':temp=5;break;
				case 'M':
				case 'N':
				case '6':
				case 'O':temp=6;break;
				case 'P':
				case 'R':
				case '7':
				case 'S':temp=7;break;
				case 'T':
				case 'U':
				case '8':
				case 'V':temp=8;break;
				case 'W':
				case 'X':
				case '9':
				case 'Y':temp=9;break;
				case '0':temp=0;break;
				case '1':temp=1;break;
				default:goto l;
			}
		resA=temp+resA*10;
		
	
		l:	ch=a[++j];
	}
	res[pos++]=resA;
	
}


///quick sort() added on 17th Aug
/*void  quicksort(int w[], int n)
{ int  key;
  int  flag;
  int *left,*right;
  int swap;
  int i,j;
  if(n==0)  return;
  i=0;j=n;
  key=0;
  flag=0;
  while(i<j)
  { if(flag==0) 
    while(i<j)
		if(w[key]<=w[j]) 
			j--; 
		else  
		{ 
			swap=w[j]; w[j]=w[key]; w[key]=swap; key=j;flag=1; 
			break;
		}
	else 
	 while(i<j)
		 if(w[key]>=w[i]) 
			 i++; 
		 else 
		{
			swap=w[i]; w[i]=w[key]; w[key]=swap; key=i;flag=0; 
			break;
		 }
  }
  left=w;
  right=&w[key+1];
  if(i-1>0)
    quicksort(left,i-1);
 if(n-i-1>0)
    quicksort(right,n-i-1);
}*/

////End
///////////main()*******

void main()
{
	freopen("a.in","r",stdin);
	int n,i;
	int flag=0;
	char dir[30];
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>dir;
		tr(dir);
	}
	//quicksort(res,n-1);
	sort(res,res+n,cmp);
	for(i=0;i<n;)
	{
		int j;
		j=i+2;
		if(res[i]==res[i+1])
		{
			while(res[i]==res[j])
				j++;
			int out=res[i]/10000;
			printf("%03d-%04d %d\n",out,res[i]%10000,j-i); 
			i=j-1;
			flag=1;
		}
		i++;
	}
	if(flag==0)
			printf("No duplicates.\n");

}






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