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

A了一天,终于过了,必贴代码,供借鉴。

Posted by a3333 at 2011-03-08 11:49:26 on Problem 1002
#include <iostream> 
#include <string>
#include <cmath>
#define PI acos(double(-1))
using namespace std;   
int main(){ 
	int n;
	char  director[200]; 
	int count[100010];
	int iss[100010];
	 
	scanf("%d",&n);
	for (int i=0;i<n;i++)
	{	iss[i]=0;
		scanf("%s",director); 
		int k=1000000;
		for (int j=0;((director[j]>='0')&&(director[j]<='9'))||((director[j]>='A')&&(director[j]<='Z'))||(director[j]=='-');j++)
		{
			if (director[j]=='A'||director[j]=='B'||director[j]=='C') {iss[i]+=2*k;k=k/10;}
			else if(director[j]=='D'||director[j]=='E'||director[j]=='F') {iss[i]+=3*k;k=k/10;}
			else if(director[j]=='G'||director[j]=='H'||director[j]=='I') {iss[i]+=4*k;k=k/10;}
			else if(director[j]=='J'||director[j]=='K'||director[j]=='L') {iss[i]+=5*k;k=k/10;}
			else if(director[j]=='M'||director[j]=='N'||director[j]=='O') {iss[i]+=6*k;k=k/10;}
			else if(director[j]=='P'||director[j]=='R'||director[j]=='S') {iss[i]+=7*k;k=k/10;}
			else if(director[j]=='T'||director[j]=='U'||director[j]=='V') {iss[i]+=8*k;k=k/10;}
			else if(director[j]=='W'||director[j]=='X'||director[j]=='Y') {iss[i]+=9*k;k=k/10;}
			else if(director[j]>='0'&&director[j]<='9') {iss[i]+=(director[j]-'0')*k;k=k/10;}  
		}
//printf("%d\n",iss[i]);
	}  
	for (int j=0;j<n;j++)
		count[j]=1;
	sort(iss,iss+n); 
	int temp=0;
	for (int i=1;i<n;i++)
	{
		if (iss[i]==iss[temp]) 
			count[temp]++;  
		else  
			iss[++temp]=iss[i];  
	}
	bool flag=false; 
	for (int j=0;j<temp+1;j++)
	{
		if (count[j]>1)
		{ 
			flag=true;
			printf("%03d-%04d %d\n",iss[j]/10000,iss[j]%10000,count[j]);
		}
		
	} 
	if(!flag) printf("No duplicates.");
	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