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 00748264 at 2008-03-11 00:07:42 on Problem 1706
拜托了!!T口T
貌似空行什么的也没有少,全为空格的空行也考虑了,我真的没办法了……
#include <iostream>
#include <cstring>
#include <stdlib.h>

using namespace std;

struct reference{
	int rank;
	char str[3][100];
};
char *end1="Works [", *end2="] can be obtained via Internet.", file[40001][100];

int comp( const void *, const void *);

int main(){
	char getin[100];
	int nRank=0, i, j, reNum, hang=0, temp;
	struct reference refer[999];
	memset(refer, 0, sizeof(refer));
	memset(file, 0, sizeof(file));
	while (cin.getline(getin, 100)){
		if (getin[0]=='\0') continue;
		for (i=0; getin[i]==' ';i++);
		if (getin[i]=='\0') continue;
		if (strstr(getin, end1)!=NULL && strstr(getin, end2)!=NULL) {
//结束语
			j=0;
			for (i=0; getin[i]!='\0';i++){
				if (getin[i]=='[') {
					file[hang][j++]='[';
					reNum=0;
					for(i++; getin[i]!=']'; i++)
						reNum= reNum*10+ getin[i]-'0';
					for (temp=refer[reNum].rank; temp>0; temp=temp/10)
						file[hang][j++]='0'+ temp%10;
				}
				file[hang][j++]=getin[i];
			}	
			file[hang++][j]='\0';
			break;
		}
		if (getin[0]=='[') {
			//the reference;
			reNum=0;
			for(i=1; getin[i]!=']'; i++)
				reNum= reNum*10+ getin[i]-'0';
			j=0;
			while(getin[0]!='\0'){
				strcpy(refer[reNum].str[j++], getin+i);
				cin.getline(getin, 100);
				i=0;
			}
		}
		else {
			//regular files record;
			while(getin[0]!='\0'){
				j=0;
				for (i=0; getin[i]!='\0';i++){
					if (getin[i]=='[') {
						nRank++;
						file[hang][j++]='[';
						for (temp=nRank; temp>0; temp=temp/10)
							file[hang][j++]='0'+ temp%10;
						reNum=0;
						for(i++; getin[i]!=']'; i++)
							reNum= reNum*10+ getin[i]-'0';
						refer[reNum].rank=nRank;
					}
					file[hang][j++]=getin[i];
				}
				file[hang][j]='\0';
				hang++;
				cin.getline(getin,100);
			}
			file[hang++][0]='\0';
		}
	}
	qsort(refer, 999, sizeof(reference), comp);
	i=0;
	while(i<=hang) 
		cout<<file[i++]<<endl;
	i=999-nRank;
	while(i<999){
		cout<<'['<<refer[i].rank;
		j=0;
		while(refer[i].str[j][0]!='\0'&&j<3)
			cout<<refer[i].str[j++]<<endl;
		cout<<endl;
		i++;
	}
	return 0;
}

int comp(const void * a, const void * b){
	return ((const reference *)a)->rank-((const reference *)b)->rank;
}
				




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