第一天:做了POJ1001(第一次觉得有点烦和难,但要坚持,万事开头难)

顺便说一下我的解题报告永远不会出现这道题的答案,只会有方法和对这道题的思考。
thinking is better than solving

首先这道题的意思很明确,就是要得到大型数据相乘的结果。
1.学习数据结构告诉我们:处理问题的两个步骤,第一保存数据,第二用好的算法去处理数据。
那么问题来了,这道题存放数据的方式是什么呢?
答案很简单数组,char还是int?网上有两种一种是直接拿char进行计算,然后直接计算,还有一种是先放进char的临时数组,再转存到int数组中去。个人认为第二种更好,因为输入的数据要经历c = c -‘0’这一步转换成int类型,所以第二种更好。(其中重要的是不要忘记判断小数点的位置)。
2.这里没有什么巧妙的算法就是要模拟手算乘法而已。
那么问题来了,手算要考虑什么东西呢?
第一要考虑的是乘法顺序:举例123*123
123
123
——-
369
246
123
=15129这样算吗?NO
是先算123然后246然后369数组顺序往后存放
第一次1 2 3
第二次1 4 7 6
第三次1 4 10 12 9
乘完之后应该是这样的
最后再从最后一位开始循环大于10就进位,进位的操作是前一个数=前一个数+后一个数/10;后一个数 = 后一个数 % 10;
最后要考虑第一位的大小因为第一位前面没有位置了。
想一想为什么要先乘完之后再进位???
3.最后不要忘记,前面的0和后面的0,剩下的细节问题,如当次数是1,底数是0等等,小数点位置,特殊情况的考虑。

举一反三:
想想乘法大数据,加法,减法,除法呢?
PS:测试数据很变态,要考虑全面而且模拟乘法的时候注意每一步的算法很容易错。java有一个处理大数据用的类,也可以实现,java朋友可以试一试,很简单哦!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
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. 输入说明 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. 输出说明 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. 输入样例 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 小提示 If you don't know how to determine wheather encounted the end of input: 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 */ { ... } 来源 East Central North America 1988 北大OJ平台(代理

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值