新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     >>计算机科学论坛<<     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 研友的交流园地,讨论关于计算机考研的方方面面。
    [返回] 计算机科学论坛计算机理论与工程『 计算机考研交流 』 → 一个这样简单的程序还是老通不过,晕哪 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 11701 个阅读者浏览上一篇主题  刷新本主题   平板显示贴子 浏览下一篇主题
     * 贴子主题: 一个这样简单的程序还是老通不过,晕哪 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     kaogejj 帅哥哟,离线,有人找我吗?
      
      
      威望:1
      等级:大二期末(C++考了100分!)
      文章:91
      积分:498
      门派:XML.ORG.CN
      注册:2008/9/24

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给kaogejj发送一个短消息 把kaogejj加入好友 查看kaogejj的个人资料 搜索kaogejj在『 计算机考研交流 』 的所有贴子 引用回复这个贴子 回复这个贴子 查看kaogejj的博客楼主
    发贴心情 一个这样简单的程序还是老通不过,晕哪

    问题:
    http://acm.pku.edu.cn/JudgeOnline/problem?id=1001
    Description

    Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the national debt is a taxing experience for many computer systems.

    This problem requires that you write a program to compute the exact value of Rn where R is a real number ( 0.0 < R < 99.999 ) and n is an integer such that 0 < n <= 25.
    Input

    The input will consist of a set of pairs of values for R and n. The R value will occupy columns 1 through 6, and the n value will be in columns 8 and 9.
    Output

    The output will consist of one line for each line of input giving the exact value of R^n. Leading zeros should be suppressed in the output. Insignificant trailing zeros must not be printed. Don't print the decimal point if the result is an integer.
    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

    If you don't know how to determine wheather encounted the end of input:
    s is a string and n is an integer

    My Java Code:

    import java.util.Scanner;
    import java.math.BigDecimal;

    public class Main {
     public static void main(String[] args) throws Exception {
      BigDecimal r;
      int n;
      String result;

      Scanner console = new Scanner(System.in);
      while (console.hasNext()) {
       r = console.nextBigDecimal();
       n = console.nextInt();
       result = r.pow(n).toPlainString();
       if(result.length() > 1){
        result = result.replaceAll("^0", "");
       }
       if (result.indexOf('.') > 0) {
        result = result.replaceAll("0+$", "");
       }
       System.out.println(result);
      }
      console.close();
     }
    }

    用我的程序运行Sample 输入的输出:
    95.123 12
    0.4321 20
    5.1234 15
    6.7592  9
    98.999 10
    1.0100 12
    548815620517731830194541.899025343415715973535967221869852721
    .00000005148554641076956121994511276767154838481760200726351203835429763013462401
    43992025569.928573701266488041146654993318703707511666295476720493953024
    29448126.764121021618164430206909037173276672
    90429072743629540498.107596019456651774561044010001
    1.126825030131969720661201

    可是提交上去报 Wrong Answer.
    不知道错在哪。。。


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2009/3/8 22:33:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 计算机考研交流 』 的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/5/3 6:47:16

    本主题贴数12,分页: [1] [2]

     *树形目录 (最近20个回帖) 顶端 
    主题:  一个这样简单的程序还是老通不过,晕哪(2554字) - kaogejj,2009年3月8日
        回复:  上面的public class Pku1001 我在提交时已改成Main,可无视。..(57字) - kaogejj,2009年3月9日
        回复:  下面的代码被Accept了:import java.util.Scanner;import j..(1006字) - kaogejj,2009年3月9日
        回复:  支持cpp。。。////////////////////////////////////////..(1329字) - ccyndi,2009年3月9日
        回复:  自己看出一个问题来if (result.indexOf('.') > 0) {应该是if (..(211字) - kaogejj,2009年3月9日
        回复:  很久以前写的,OJ上的Archive下载不下来,刚在电脑上找出来一份,不知道是不是最后AC的版本:..(1072字) - dark_matter,2009年3月9日
            回复:  ACM上你可查看自己的代码啊[quote][b]以下是引用[i]dark_matter在200..(1217字) - kaogejj,2009年3月9日
        回复:  如果你一定要用java的话,那么还应该用BigDecimal的stripTrailingZeros..(132字) - greatseven,2009年3月9日
        回复:  看法同楼上,这种大数乘法可以用数组解决,在《程序设计导引及在线实践》里面有例子。..(80字) - mychangle1234,2009年3月9日
        回复:  这个题的问题多了少小看1001了出了名的无限WA不看你程序光看你结果是WA就知道你至少犯了其..(283字) - whasic,2009年3月9日
        回复:  不懂java不过我看上面写的Java is J2SE 1.5,会不会不兼容。。。呵呵..(66字) - dq85,2009年3月9日
        回复:  我也遇到了,求解(16字) - alis1017,2009年3月9日

    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    62.500ms