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

那位帮忙看看 java写的 为何会Runtime error 呀

Posted by jinbi at 2008-11-01 20:42:07 on Problem 1047
import java.io.*;
import java.util.*;
import java.math.BigDecimal;

public class Main {
	public static void main(String args[])throws IOException{
		Scanner cin=new Scanner(System.in);
		String str,s;
		int len,i,j,tag;
		char c,ch[]=new char[100],ch1[]=new char[100];
		BigDecimal big,big1,res[]=new BigDecimal[2];
		
		while((str=cin.next())!=null){
			len=str.length();
			c=str.charAt(0);  tag=0;
			for(i=1;i<len;i++){
				if(str.charAt(i)<c){
					tag=i;
					c=str.charAt(tag);
				}
			}
			int r=tag;
			for(i=0;i<len;i++){
				r=tag-i;
				if(r<0) r+=len;
				if(str.charAt(r)>c) break;
			}
			r=(r+1)%len;
			for(i=0;i<len;i++){
				ch[i]=str.charAt((r+i)%len);
			}
			//ch[len]='\0';
			s=new String(ch,0,len);
			//System.out.println(s);
			if(!str.equals(s)) {
				System.out.println(str+" is not cyclic");
				continue;
			}
			big=new BigDecimal(s);
			if(big.equals(BigDecimal.ZERO)){
				System.out.println(str+" is cyclic");
				continue;
			}
			for(i=1;i<len;i++){
				for(j=0;j<len;j++){
					ch1[j]=ch[(j+i)%len];
				}
				big1=new BigDecimal(ch1,0,len);
				res=big1.divideAndRemainder(big);
				//System.out.println(res[0]+" "+res[1]);
				if(res[1].equals(BigDecimal.ZERO)){
					if(res[0].compareTo(big)>0) break;
				}
				else break;				
			}
			if(i>=len)
				System.out.println(str+" is cyclic");
			else System.out.println(str+" is not cyclic");
		}
	}
}
 

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