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 00748008 at 2008-03-16 23:10:07 on Problem 1706
#include<iostream>
#include<cstring>
#include<cstdlib>
using namespace std;

struct SDis
{
	char aText[3][100];
	int ID;
}Dis[1005];

int CompareDis(const void *p1,const void *p2)
{
	return ((struct SDis *)p1)->ID - ((struct SDis *)p2)->ID;
}

bool IsEmptyline(const char *szTemp)
{
	int n=strlen(szTemp),i;
	for(i=0;i<n;i++) 
		if(szTemp[i]!=' ') 
			return false;
	return true;
}

int GetNum(char *p1,char *p2)
{
	char *p;
	int k=0;
	for(p=p1+1;p<p2;p++)
		k=k*10+(*p-'0');
	return k;
}


int main()
{
	char aReg[40001][100],szTemp[100],temp[100],*pLeft,*pRight;
	int i,k,nDis=0,nRegLine=0,nReference=0,aReference[1005]={0};	
	memset(Dis,0,sizeof(Dis));
	while(cin.getline(szTemp,100))
	{
		if(szTemp[0]=='[')
		{
			i=0;
			do
			{
				if(IsEmptyline(szTemp))
					break;
				strcpy(Dis[nDis].aText[i++],szTemp);
			}
			while(cin.getline(szTemp,100));
			nDis++;
		}
		else if(IsEmptyline(szTemp))
			continue;
		else
		{
			do
			{
				if(IsEmptyline(szTemp))
				{
					aReg[nRegLine++][0]='\0';
					break;
				}
				strcpy(aReg[nRegLine++],szTemp);
			}
			while(cin.getline(szTemp,100));
		}
	}
	for(i=0;i<nRegLine;i++)
	{
		pRight=aReg[i];
		while((pLeft=strchr(pRight,'['))!=NULL)
		{
			pRight=strchr(pLeft,']');
			k=GetNum(pLeft,pRight);
			if(!aReference[k])
			{
				nReference++;
				aReference[k]=nReference;
			}
			sprintf(szTemp,"%d",aReference[k]);
			strcpy(temp,pRight);
			strcpy(pLeft+1,szTemp);
			strcat(aReg[i],temp);
		}
	}
	for(i=0;i<nDis;i++)
	{
		pRight=strchr(Dis[i].aText[0],']');
		k=GetNum(Dis[i].aText[0],pRight);
		Dis[i].ID=aReference[k];
		sprintf(szTemp,"%d",aReference[k]);
		strcpy(temp,pRight);
		strcpy(Dis[i].aText[0]+1,szTemp);
		strcat(Dis[i].aText[0],temp);
	}
	qsort(Dis,nDis,sizeof(struct SDis),CompareDis);
	for(i=0;i<nRegLine;i++)
		cout<<aReg[i]<<endl;
	if(nRegLine&&strlen(aReg[nRegLine-1])) cout<<endl;
	for(i=0;i<nDis;i++)
	{
		k=0;
		while(k<3&&strlen(Dis[i].aText[k]))
			cout<<Dis[i].aText[k++]<<endl;
		cout<<endl;
	}
	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