源码

1001. A+B Format (20)
时间限制 400 ms
内存限制 65536 kB
代码长度限制 16000 B
判题程序 Standard
作者 CHEN, Yue Calculate a + b and output the sum in standard format --
that is, the digits must be separated into groups of three by commas (unless there are less than four digits). Input
Each input file contains one test case.
Each case contains a pair of integers a and b where -1000000 <= a, b <= 1000000.
The numbers are separated by a space. Output
For each test case, you should output the sum of a and b in one line.
The sum must be written in the standard format. Sample Input
-1000000 9
Sample Output
-999,991

解题过程

  • 题意:求A+B的值,并以标准格式输出,即从右往左每3位数用','隔开。
  • 思考过程:先不考虑正负,最后再加上符号。最开始想利用数组,将各个位上的数存入一个数组中,但我想到的处理方法太繁琐,所以放弃这种方法。后来想到只要将每3位分割出来就可以了。因为 -1000000 <= a, b <= 1000000,所以-2000000<a+b<2000000,最多就出现x,xxx,xxx这种情况。后3位数abs(a+b)%1000,中间3位数abs(a+b)/1000%1000,前面那一位数abs(a+b)/1000000。
  • 编码完后的调试:选取比较特别的几个数自己进行测试。例如 (0) (xx) (x,xxx) (x,xxx,xxx),最初由于if中的条件没写好会出现没有输出或者多组输出的情况,对条件修改后没有这种情况发生。将这些问题解决后提交OJ,一次通过。



PDF

最新文章

  1. Jump Game 的三种思路 - leetcode 55. Jump Game
  2. VC++编程之对话框贴图
  3. Error 56: …… VPN Service has not been started
  4. POJ 2524 :Ubiquitous Religions
  5. ios ios7 取消控制拉升
  6. 每天收获一点点------Hadoop基本介绍与安装配置
  7. 大数据系列修炼-Scala课程11
  8. python基础——匿名函数及递归函数
  9. .netcore使用SocketAsyncEventArgs Pool需要注意!
  10. Java的static类
  11. ZKWeb网页框架1.9正式发布
  12. Sitecore CMS中更改项目的模板
  13. SVG:中国地图
  14. SRM466
  15. Python Word2Vec使用训练好的模型生成词向量
  16. List&lt;String&gt; bikeList = Arrays.asList(bikeuuids);
  17. 没有装delphi软件则须修改程序的Uses单元,去掉QDialogs qtintf.dll
  18. 【PyQt5 学习记录】005:QMainWindow 及状态栏、菜单栏和工具栏
  19. Onvif获取rstp地址GetCapabilities能力时,出现error 4或者52的的解决方法
  20. 【BZOJ1502】【NOI2005】月下柠檬树

热门文章

  1. block本质探寻六之修改变量
  2. iOS url出现特殊字符处理 -- stringByAddingPercentEncodingWithAllowedCharacters
  3. 【Len&#39;s DMG】macOS Mojave 10.14.1 正式版 18B75 With Clover 4726原版镜像
  4. day 92 跨域和CORS
  5. lua io操作(一)
  6. 20155238 2016-2017-2 《Java程序设计》第四周学习总结
  7. 课下测试补交(ch03 ch08)
  8. Spring boot ---- java.lang.NoClassDefFoundError: javax/servlet/ServletContext
  9. 获取当前页面的所有链接的四种方法对比(python 爬虫)
  10. iOS开发-通过正则表达式判断字符串是否为纯阿拉伯数字