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

为什么用C++就wa,是哪个地方两种编译器处理存在差别?

Posted by Hzj_jie at 2006-01-06 16:36:30 on Problem 1520
代码如下,望高手支点。多谢

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

char strWord[1024][81];
bool isNumber[1024];
const int intSizeOfIsNumber=sizeof(isNumber);
int intLen[1024];
int intWordCount;
const int intUCaseToLCase='A'-'a';

bool CheckNumber(char * strInput)
{
	if((strInput[0]<='9' && strInput[0]>='0') || strInput[0]=='-')
		return true;
	else
		return false;
}

void lcase(char * strInput,int intLen)
{
	int i;
	for(i=0;i<intLen;i++)
	{
		if(strInput[i]<='Z' && strInput[i]>='A')
		{
			strInput[i]-=intUCaseToLCase;
		}
	}
}

void StrToInt(int intSrc,char * strDest,int intStart,int & intNewLen)
{
	bool isNotZero=false;
	int i;
	intNewLen=0;
	for(i=intStart;i<intLen[intSrc];i++)
	{
		if(isNotZero==true || strWord[intSrc][i]!='0')
		{
			strDest[intNewLen++]=strWord[intSrc][i];
			isNotZero=true;
		}
	}
	strDest[intNewLen]='\0';
}

bool isSmaller(int intIndex1,int intIndex2)
{
	char strCmp[2][81];
	int intCmpLen[2];
	if(isNumber[intIndex1]==true)
	{
		if(strWord[intIndex1][0]=='-' && strWord[intIndex2][0]!='-')
			return true;
		else if(strWord[intIndex1][0]!='-' && strWord[intIndex2][0]=='-')
			return false;
		else if(strWord[intIndex1][0]=='-')
		{
			StrToInt(intIndex1,strCmp[0],1,intCmpLen[0]);
			StrToInt(intIndex2,strCmp[1],1,intCmpLen[1]);
			if(intCmpLen[0]>intCmpLen[1])
				return true;
			else if(intCmpLen[0]<intCmpLen[1])
				return false;
			else
			{
				if(strcmp(strCmp[0],strCmp[1])>0)
					return true;
			}
		}
		else
		{
			StrToInt(intIndex1,strCmp[0],0,intCmpLen[0]);
			StrToInt(intIndex2,strCmp[1],0,intCmpLen[1]);
			if(intCmpLen[0]<intCmpLen[1])
				return true;
			else if(intCmpLen[0]>intCmpLen[1])
				return false;
			else
			{
				if(strcmp(strCmp[0],strCmp[1])<0)
					return true;
			}
		}
		
		return false;
	}
	else
	{
		strcpy(strCmp[0],strWord[intIndex1]);
		strcpy(strCmp[1],strWord[intIndex2]);
		lcase(strCmp[0],intLen[intIndex1]);
		lcase(strCmp[1],intLen[intIndex2]);
		if(strcmp(strCmp[0],strCmp[1])<0)
			return true;
		else
			return false;
	}
}

void Exchange(int intIndex1,int intIndex2)
{
	char strOther[81];
	int intOtherLen=intLen[intIndex1];
	strcpy(strOther,strWord[intIndex1]);
	strcpy(strWord[intIndex1],strWord[intIndex2]);
	intLen[intIndex1]=intLen[intIndex2];
	intLen[intIndex2]=intOtherLen;
	strcpy(strWord[intIndex2],strOther);
}

int main()
{
	int i,j;
	bool isBreak=false;
	
	scanf("%s",strWord[0]);
	while(strWord[0][0]!='.')
	{
		memset(isNumber,false,intSizeOfIsNumber);
		intLen[0]=strlen(strWord[0])-1;
		isBreak=(strWord[0][intLen[0]]=='.');
		strWord[0][intLen[0]]='\0';
		isNumber[0]=CheckNumber(strWord[0]);
		intWordCount=1;
		while(isBreak==false)
		{
			scanf("%s",strWord[intWordCount]);
			intLen[intWordCount]=strlen(strWord[intWordCount])-1;
			isBreak=(strWord[intWordCount][intLen[intWordCount]]=='.');
			strWord[intWordCount][intLen[intWordCount]]='\0';
			isNumber[intWordCount]=CheckNumber(strWord[intWordCount++]);
		}
		
		for(i=1;i<intWordCount;i++)
		{
			for(j=0;j<i;j++)
			{
				if(isNumber[i]==isNumber[j] && isSmaller(i,j)==true)
				{
					Exchange(i,j);
				}
			}
		}
		
		for(i=0;i<intWordCount;i++)
		{
			printf("%s",strWord[i]);
			if(i<intWordCount-1)
				printf(", ");
			else
				printf(".\n");
		}
		
		scanf("%s",strWord[0]);
	}
	
	return 1;
}

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