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

runtime error...我哪里错了啊。。。

Posted by demonpoj at 2012-08-12 10:00:28 on Problem 1146
先由后至前找到逆序的一个。
从后面选出最小的跟他交换。
断点处之后的数组重新排序。。。。



package p1146;

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		while(true){
			Scanner input = new Scanner(System.in);
			char[] in = input.next().toCharArray();
			char[] in2 = new char[50];
			char mid;
			for (int i=0; i<in.length;i++){
			mid = in[i];
			in2[i] = mid;
			}
		 		
			if (in[0] == '#'){
				System.exit(0);	 
			}
			else {
				/*
				for (int i=0; i<in.length; i++){
					System.out.print(in[i]);
				}
				*/
				char temp, temp2, temp3;
				int flag;
				for (int i=in.length-1; i>0; i--){
					if (in[i]>in[i-1]){
						temp = in[i];
						flag = i;
						for (int j=in.length-1; j>i; j--){
							if (in[j] <= temp && in[j] > in[i-1]){
								temp = in[j];
								flag = j;	
							}	
						}
						temp2 = in[i-1];
						in[i-1] = temp;
						in[flag] = temp2;
						
						//排序部分
						for (int k=in.length-1; k>i; k--){
							for (int m=k; m>=i; m--){
								if (in[m]>in[k]){
									temp3 = in[m];
									in[m] = in[k];
									in[k] = temp3;
								}	
							}	
						}
						
						break;
					}	
				}
				
				//判定及输出
				flag = 0;
				for (int i=0; i<in.length; i++){
					if(in[i]==in2[i]){
						flag++;
					}	
				}
				if(flag == in.length){
					System.out.println("No Successor");	
					System.gc();
				}
				
				else {
					for (int i=0; i<in.length; i++){
						System.out.print(in[i]);	
					}	
					System.out.println();
					System.gc();
					
				}
			}

			
		}
	}
}

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