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求助____________狂RE,是输入问题么...import java.io.*; import java.util.*; import java.math.*; public class Main { public static void main(String args[]) throws Exception { String s,res,temp; Scanner in=new Scanner(System.in); int i,j,k,value; boolean flag,is; while((s=in.next())!=null) { i=in.nextInt(); value=0; flag=false; BigDecimal a=new BigDecimal(s.trim()); res=a.pow(i).toPlainString(); for(j=0;j<res.length();j++) { if(res.charAt(j)!='.') value=value*10+res.charAt(j)-'0'; else { flag=true; if(value!=0) { temp=res.substring(0, j); System.out.print(temp); } break; } } if(flag) { is=false; temp=res.substring(j+1); for(k=0;k<temp.length();k++) if(temp.charAt(k)!='0') {is=true;break;} if(is) { System.out.print('.'); for(k=temp.length()-1;k>=0;k--) { if(temp.charAt(k)!='0')break; } System.out.println(temp.substring(0,k+1)); } } else System.out.println(res); } } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator