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一直wa

Posted by ccy_Johnson at 2009-07-13 22:16:57 on Problem 1002
#include "stdio.h"

int read();

main()
{
	int n, i, j, k, step;
	int number[100000], temp;
	int f[100000], num[50000], m;
	scanf("%d", &n);
	for(i=0; i<n; i++)
	{
		number[i]=read();
		f[i]=0;
	}

	m=0;
	for(i=0; i<n; i++)
	{
		if(f[i]!=0) continue;
		temp=1;
		for(j=i+1; j<n; j++)
		{
			if(f[i]!=0) continue;
			if(number[j]==number[i])
			{
				temp++;
				f[j]=-1;
			}
		}
		f[i]=temp;
		if(f[i]>1)
		{
			num[m]=number[i]*10+f[i];
			m++;
		}
	}


	for(step=m/3;step>1;step/=3)
	{
		for(i=step;i<m;i++)
		{
			temp=num[i];
			for(j=i-step; j>=0 && num[j]>temp; j-=step)
				num[j+step]=num[j];
			if(j+step-i) num[j+step]=temp;
		}
	}
	for(i=1;i<m;i++)
	{
		temp=num[i];
		for(j=i-1;j>=0 && num[j]>temp;j--)
			num[j+1]=num[j];
		if(j+1-i) num[j+1]=temp;
	}

	for(i=0; i<m; i++)
	{
		temp=num[i];
		printf("%d", temp/10000000); temp%=10000000;
		printf("%d", temp/1000000); temp%=1000000;
		printf("%d-", temp/100000); temp%=100000;
		printf("%d", temp/10000); temp%=10000;
		printf("%d", temp/1000); temp%=1000;
		printf("%d", temp/100); temp%=100;
		printf("%d %d\n", temp/10, temp%10);
	}
	if(m==0) printf("No duplicates.\n");
}

int read()
{
	int i, a, number=0, k=1000000;
	char s;
	for(i=0; i<7; )
	{
		scanf("%c", &s);
		if(s>='A' && s<='Z' && s!='Q' && s!='Z' || s>='0' && s<='9' || s>='a' && s<='z' && s!='q' && s!='z' )
		{
			if(s>='A' && s<='C' || s>='a' && s<='c' ) a=2;
			else if(s>='D' && s<='F' || s>='d' && s<='k') a=3;
			else if(s>='G' && s<='I' || s>='g' && s<='i') a=4;
			else if(s>='J' && s<='L' || s>='j' && s<='l') a=5;
			else if(s>='M' && s<='O' || s>='m' && s<='o') a=6;
			else if(s>='P' && s<='S' || s>='p' && s<='s') a=7;
			else if(s>='T' && s<='V' || s>='t' && s<='v') a=8;
			else if(s>='W' && s<='Y' || s>='w' && s<='y') a=9;
			else a=s-'0';
			number+=a*k;
			i++;
			k/=10;
		}
	}
	return number;
}

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