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

PE的进

Posted by donkeyinacm at 2010-02-23 15:02:04 on Problem 1706
//注意下面isBlankLine函数的调用




#include <iostream>
#include <map>
using namespace std;
#define MAXRD 1000
#define MAXRDL 250

map<int,int> M;
struct rd
{
	rd()
	{
		con=new char[MAXRDL];
	}
	int num;
	char *con;
};

rd R[MAXRD];
int rdn,nCount;

int cmp(const void *a,const void*b)
{
	return M[static_cast<const rd*>(a)->num]-M[static_cast<const rd*>(b)->num];
}

int convert(char *str,bool bprint)
{
	int j,i,k,sum,bei;
	int len=strlen(str);
	for(i=0;i<len;i++)
	{
		if(str[i]=='[')
		{
			sum=0;
			bei=1;
			j=i+1;
			while(str[j]!=']')
				j++;
			for(k=j-1;k>=i+1;k--)
			{
				sum+=(str[k]-'0')*bei;
				bei=bei*10;
			}
	//		printf("DEGUG:%d",sum);
            if(bprint)
			if(M.find(sum)==M.end())
			{
				M[sum]=nCount++;
			}
			if(bprint)
				printf("[%d]",M[sum]);
			else
				return sum;
			i=j;
		}
		else
			printf("%c",str[i]); 
	}
	return -1;
}

bool isBlankLine(char *str)
{
 int len=strlen(str);
 int i;
 for(i=0;i<len;i++)
	 if(str[i]!=' ')
    return false;
return true;
}

int main()
{
	freopen("c:/aaa.txt","r",stdin);
//	freopen("c:/2.txt","w",stdout);
	M.clear();
	int i,j;
	rdn=-1;
	nCount=1;
	char *str=new char[100];
	bool brd,first=true;
	while(gets(str)!=NULL)
	{
        while(isBlankLine(str)&&gets(str)!=NULL)
              ;
		if(isBlankLine(str))
			break;
		if(str[0]=='[')
		{
			brd=true;
			rdn++;
			R[rdn].num=convert(str,false);
			strcpy(R[rdn].con,str);
			while(gets(str)!=NULL&&!isBlankLine(str))
			{
                R[rdn].con=strcat(R[rdn].con,"\n");
				R[rdn].con=strcat(R[rdn].con,str);
			}
		}
		else
		{
			if(!first)
				printf("\n");
			first=false;
			brd=false;
			convert(str,true);
			printf("\n");
			while(gets(str)!=NULL&&!isBlankLine(str))
			{
				convert(str,true);
				printf("\n");
			}
			//	printf("\n");
		}
		str[0]='\0';
	}
	
    qsort(R,rdn+1,sizeof(R[0]),cmp);
    for(i=0;i<=rdn;i++)
	{
		printf("\n");
		j=0;
		while(R[i].con[j]!=']')
			j++;
		printf("[%d]",M[R[i].num]);
		printf("%s",R[i].con+j+1);
			printf("\n");
	}
//	printf("\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