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 yuenyun at 2003-07-09 15:10:26 on Problem 1002
#include <iostream>
#include <stdlib.h>
//#include <search.h>
using namespace std;
	int a[100000];
	char b[40];


int cmp(const void *t1,const void *t2)                                     
 {int *a,*b; 
  a=(int *)t1; b=(int *)t2; 
  if (*a>*b) return 1; 
  if (*a<*b) return -1; 
  return 0; 
 } 

void main()
{

	int num;
	cin>>num;
	if (num<2)
   {
		cin>>b;
	    cout<<"No duplicates.";
	}
	else 
	{
	for (int i=0;i<num;i++)
	{
		cin>>b;
 			int result=0;
		for (int j=0;j<strlen(b);j++)
		{
				switch(b[j])
				{
				case('A'):
				case('B'):
				case('C'):
					{
						b[j]='2';
					    break;
					}
				case('D'):
				case('E'):
				case('F'):
					{
						b[j]='3';
						break;
					}
				case('G'):
				case('H'):
				case('I'):
					{
						b[j]='4';
						break;
					}
				case('J'):
				case('K'):
				case('L'):
					{
						b[j]='5';
						break;
					}
				case('M'):
				case('N'):
				case('O'):
					{
						b[j]='6';
						break;
					}
				case('P'):
				case('R'):
				case('S'):
					{
						b[j]='7';
						break;
					}
				case('T'):
				case('U'):
				case('V'):
					{
						b[j]='8';
						break;
					}
				case('W'):
				case('X'):
				case('Y'):
					{
						b[j]='9';
						break;
					}

			
				}
	

				  if (b[j]>='0'  &&  b[j]<='9')
				  {
					 // b[p1++]=b[j];
					  result=10*result+b[j]-('1'-1);
				  }
		}
		a[i]=result;
	}
  qsort(a,num,sizeof(int),cmp);

  int flag=0;                //是否是不存在有重复的串
  int pp=0;
	while(pp<num)			//记数指针pp遍历num一遍而已,不算多吧
	{
		int sum=1;
		int i=1;
		while(a[pp]==a[pp+i])   //只是记录重复的串个数,其并不重复记,因为它往后移动时,PP会动所以
								//其外部循环并没有累计记数,即它和外部大循环在一起才记了NUM次;
		{
			i++;
			sum++;
		}
		if (sum>1)              //如果记数值大于1那么就输出;
		{
		    int x1=a[pp]/10000;          //前3位
			int y1=a[pp] % 10000;		 //后4位
	
			if (x1>99)                   //如果前三位不足,看其有几位之前用0补足3位;   
			         cout<<x1<<"-";
			else if (x1>9)
			        cout<<"0"<<x1<<"-";
			else 
				cout<<"00"<<x1<<"-";

			if (y1>999)					//如果后4位不足,看其有几位用0补足4位;
				cout<<y1<<" "<<sum<<endl;
			else if (y1>99)
				cout<<"0"<<y1<<" "<<sum<<endl;
			else if (y1>9)
				cout<<"00"<<y1<<" "<<sum<<endl;
			else if (y1>=0)
				cout<<"000"<<y1<<" "<<sum<<endl;
				flag=1;					//只要有一组多于2个的串就将标志FLAG为1;

			}
		
        pp=pp+i;
	}
if (flag==0)                          //整个大循环完了后,看FLAG如为0则输出。。。  
  cout<<"No duplicates.";
	}
}

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