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

Re:请犇人指点啊,我已经被wa无数次了(自知编得不好,大家不要笑话)

Posted by xfxyjwf at 2006-03-14 19:12:33 on Problem 1706
In Reply To:Re:请犇人指点啊,我已经被wa无数次了(自知编得不好,大家不要笑话) Posted by:salukaya at 2006-03-13 23:33:18
建议先做些容易些的题目.
学什么都得慢慢来的.
ps:注意代码的"排版":)

> #include<iostream.h>
> #include<string.h>
> 
> 
> void main()
> {
> 	char* t[40000];
> 	int* mark;
> 	for(int i=0;;i++)
> 	{
> 		char temp[81];
> 		cin.getline(temp,80,'\n');
> 		if(!strcmp(temp,""))
> 			break;
> 		t[i]=new char[strlen(temp)];
> 		strcpy(t[i],temp);
> 	}//right
> 	mark=new int[i];
> 	int l=i,m=0,count=0,p=0,j=0;
> 	for(i=0;i<l;i++)
> 	{
> 		for(int e=0;t[i][e]==' '&&e<strlen(t[i]);e++);
>         if(t[i][e]=='\0'){
> 			mark[i]=0;
> 			continue;
> 		}
> 		else if((i==0&&t[i][0]=='[')||(mark[i-1]==0&&t[i][0]=='[')){
> 			count++;
> 			for(;;i++){
> 				for(int e=0;t[i][e]==' '&&e<strlen(t[i]);e++);
>                 if(t[i][e]=='\0') break;
>     			mark[i]=2;
> 			}
> 			i--;
> 			continue;
> 		}
> 		else
> 			mark[i]=1;
> 	}
> 	//right
> 	int* num=new int[count];
> 	for(i=0;i<l;i++){
> 		if(mark[i]==2) continue;
> 		if(mark[i]==1){
> 			for(j=0;j<strlen(t[i]);j++){
> 				if(t[i][j]!='[') cout<<t[i][j];
> 				if(t[i][j]=='['){
> 					num[m]=0;
> 					int sort=0;
> 					cout<<"[";
> 					for(j=j+1;t[i][j]!=']';j++){
> 						num[m]=num[m]*10+(t[i][j]-'0');}
> 					for(int a=0;a<m;a++){
> 						if(num[m]==num[a]){
> 							sort=1;
> 							cout<<a+1<<"]";}
> 						if(sort)
> 							m--;
> 					}
> 					if(!sort)
> 						cout<<m+1<<"]";
> 					m++;
> 				}
> 			}
> 			cout<<endl;
> 			continue;
> 		}
> 		if(i>0&&mark[i-1]==1&&mark[i]==0)
> 		{
> 			cout<<endl;
> 			for(;mark[i]==0&&i<l;i++);
> 			i--;
> 		}
> 	}
> 	int an=0;
> 	int q=0,k=0;
> 	for(k=0;k<count;k++){
> 		for(i=0;i<l;i++){
> 			if(mark[i]==2&&t[i][0]=='['){
> 				an=0;
> 				for(j=1;t[i][j]!=']';j++)
> 					an=an*10+(t[i][j]-'0');
> 			    if(an!=num[k]) continue;
> 			    if(an==num[k]){
> 			    	cout<<"["<<k+1;
> 				    for(;j<strlen(t[i]);j++)
> 				    	cout<<t[i][j];
> 			    	cout<<endl;
> 					i++;
> 			    	for(;mark[i]==2;i++)
> 		    			cout<<t[i]<<endl;
> 			     	i--;
> 				}
> 				cout<<endl;
> 			}
> 		}
> 	}
> 	delete[] mark;
> }

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