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 loop111 at 2009-09-16 19:54:49 on Problem 1002
/************************************************************************/
/*author: Wencan Luo(loop111@gmail.com)                                 */
/*date:		2009-09-16													*/
/************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MaxSize 1024
#define MaxNum 8
#define MaxInputLen 100001

char szInput[MaxInputLen][MaxNum];
char szNum[MaxNum];
const char turn[27] = {"2223334445556667@77888999@"};

int isDigit(char c)
{
	if ( c>='0' && c<='9') return 1;	
	return 0;
}

int ProcessOne(char* szLine)
{
	int nLen = 0;
	int i,k;
	char ch;

	memset(szNum,0,MaxNum);
	nLen = strlen(szLine);

	for (i=0,k=0;i<nLen;i++)
	{
		ch = szLine[i];
		
		if (ch == '-') continue;
		else if (isDigit(ch)==1)
		{
			szNum[k++] = ch;
		}
		else
		{
			szNum[k++] = turn[ch-'A'];
		}
	}
	
	return 0;
}

void Out(char* str,int count)
{
	int j;
	
	for (j=0;j<3;j++)
	{
		printf("%c",str[j]);
	}
	printf("-");
	for (j=3;j<8;j++)
	{
		printf("%c",str[j]);
	}
	printf(" %d\n",count);
}

int main(int argc,char* argv[])
{
	//freopen("A.in","r",stdin);
	
	char szLine[MaxSize];
	int i,j;
	int testcase;
	int caseId;
	int res;
	char tmp[MaxNum];
	int flag = 1;
	int count;

	memset(szInput,0,MaxInputLen*MaxNum);

	scanf("%d",&testcase);
	for (caseId=0;caseId<testcase;caseId++)
	{
		res = 0;
		scanf("%s",szLine);
		res = ProcessOne(szLine);

		strcpy(szInput[caseId],szNum);
	}
	
	//sort
	for (i=0;i<testcase;i++)
	{
		for (j=i+1;j<testcase;j++)
		{
			if (strcmp(szInput[i],szInput[j]) >0)
			{
				strcpy(tmp,szInput[i]);
				strcpy(szInput[i],szInput[j]);
				strcpy(szInput[j],tmp);
			}
		}
	}

	for (i=0;i<testcase;i++)
	{
		count = 1;
		
		while (i<testcase && strcmp(szInput[i+1],szInput[i])==0)
		{
			i++;
			count++;
		}
		if (count == 1) continue;
		flag = 0;

		Out(szInput[i],count);
	}
	
	if (flag == 1)
	{
		printf("No duplicates.\n");
	}
	
	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