Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
那位帮忙看看 java写的 为何会Runtime error 呀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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator