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

终于A了,但是还是不明白为什么字母小的要排在前面

Posted by denganliang at 2011-03-29 10:56:56 on Problem 3617
In Reply To:大家都说是水题,可是我还是没有思路阿 Posted by:denganliang at 2011-03-28 21:40:48
#include <stdio.h>
#include <string.h>
int main(){
   int n,i,j,k,c,d,flag;
   char a[2001],b[2001];
   memset(a,'\0',2001);
   memset(a,'\0',2001);
   scanf("%d",&n);
   for(i=0;i<n;i++){ 
     getchar();	
     a[i]=getchar();
    }
   k=0;
   if(n==1) {
	   printf("%c\n",a[0]);
	   return 0;
	   }
   for(i=0,j=n-1;i<=j;){
	   if(a[i]>a[j]){
		   b[k++]=a[j--];
		   }
		else if(a[i]<a[j]){
			b[k++]=a[i++];
			}
	    else{
			flag=0;
            if(i!=j){
			for(c=i+1,d=j-1;c<d;c++,d--){
				
				if(a[c]>a[d]){
					b[k++]=a[j--];
					flag=1;
					break;
					}
			    else if(a[c]<a[d]){
					b[k++]=a[i++];
					flag=1;
					break;
					}
				}
			}
				if(flag==0) b[k++]=a[i++]; 
			}       
	   }
	   
	   b[k]='\0';
	   for(i=0;i<n;){
		   printf("%c",b[i]);
		   if((++i)%80==0) 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