北大ACM1001 rentime error 下面java代码哪里有问题呀
importjava.io.*;importjava.math.*;publicclassacm1001{publicstaticvoidmain(String[]arg...
import java.io.*;
import java.math.*;
public class acm1001 {
public static void main(String[] args) throws IOException {
BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));
String str = "";
while ((str = cin.readLine()).length() > 0) {
BigDecimal de=new BigDecimal(str.substring(0,6).trim());
int po=new Integer(str.substring(7).trim());
String re=de.pow(po).toPlainString();
if(de.compareTo(new BigDecimal("0")) == 0) {
System.out.print(0);
continue;
}
String[] re1=re.split("[.]");
if(re1.length==1||Integer.parseInt(re1[1])==0){
System.out.println(re1[0]);
continue;
}
else if(Integer.parseInt(re1[0])==0){
System.out.println("."+re1[1]);
}
else{
System.out.println(re);
}
}
}
} 展开
import java.math.*;
public class acm1001 {
public static void main(String[] args) throws IOException {
BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));
String str = "";
while ((str = cin.readLine()).length() > 0) {
BigDecimal de=new BigDecimal(str.substring(0,6).trim());
int po=new Integer(str.substring(7).trim());
String re=de.pow(po).toPlainString();
if(de.compareTo(new BigDecimal("0")) == 0) {
System.out.print(0);
continue;
}
String[] re1=re.split("[.]");
if(re1.length==1||Integer.parseInt(re1[1])==0){
System.out.println(re1[0]);
continue;
}
else if(Integer.parseInt(re1[0])==0){
System.out.println("."+re1[1]);
}
else{
System.out.println(re);
}
}
}
} 展开
1个回答
展开全部
给你个已经AC的代码吧
import java.util.*;
import java.math.*;
public class Main
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
BigDecimal R;
int n;
String s;
while(in.hasNext())
{
R = in.nextBigDecimal();
n = in.nextInt();
R = R.pow(n).stripTrailingZeros();
s = R.toPlainString();
if(s.charAt(0)=='0')
s=s.substring(1);
System.out.println(s);
}
}
}
注意: oj上用Java主类只能叫Main
没仔细看你的代码, 不过你的代码运行时会抛异常. 原因可能是re1[1]超出了int可以表示的范围.
import java.util.*;
import java.math.*;
public class Main
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
BigDecimal R;
int n;
String s;
while(in.hasNext())
{
R = in.nextBigDecimal();
n = in.nextInt();
R = R.pow(n).stripTrailingZeros();
s = R.toPlainString();
if(s.charAt(0)=='0')
s=s.substring(1);
System.out.println(s);
}
}
}
注意: oj上用Java主类只能叫Main
没仔细看你的代码, 不过你的代码运行时会抛异常. 原因可能是re1[1]超出了int可以表示的范围.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询