Time Limit: 500MS | Memory Limit: 10000K | |
Total Submissions: 120361 | Accepted: 29377 |
Description
This problem requires that you write a program to compute the exact value of R n where R is a real number ( 0.0 < R < 99.999 ) and n is an integer such that 0 < n <= 25.
Input
Output
Sample Input
95.123 12 0.4321 20 5.1234 15 6.7592 9 98.999 10 1.0100 12
Sample Output
548815620517731830194541.899025343415715973535967221869852721 .00000005148554641076956121994511276767154838481760200726351203835429763013462401 43992025569.928573701266488041146654993318703707511666295476720493953024 29448126.764121021618164430206909037173276672 90429072743629540498.107596019456651774561044010001 1.126825030131969720661201
Hint
s is a string and n is an integer
C++ while(cin>>s>>n) { ... } c while(scanf("%s%d",s,&n)==2) //to see if the scanf read in as many items as you want /*while(scanf(%s%d",s,&n)!=EOF) //this also work */ { ... }
Source
import java.math.BigDecimal;
import java.util.Scanner;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input=new Scanner(System.in);
while(input.hasNext()){
int i;
BigDecimal a=BigDecimal.valueOf(input.nextDouble()).pow(input.nextInt());
String str=a.toPlainString();
str=F(str);
System.out.println(str);
}
}
private static String F(String str) {
// TODO Auto-generated method stub
int i;
if(str.indexOf(".")!=-1){//是否为小数,为小数时
while(str.endsWith("0"))//如果小数结尾是0,去0,直到结尾不为0
str=str.substring(0,str.length()-1);
if(str.endsWith("."))//如果结尾是小数点‘.’,去小数点
str=str.substring(0, str.length()-1);
if(str.indexOf(".")!=-1&&str.startsWith("0"))//判断是否为“0.777”,这种情况
str=str.substring(1,str.length());
}
return str;
}
}