Little Boxes

  Little boxes on the hillside. 
  Little boxes made of ticky-tacky. 
  Little boxes. 
  Little boxes. 
  Little boxes all the same. 
  There are a green boxes, and b pink boxes. 
  And c blue boxes and d yellow boxes. 
  And they are all made out of ticky-tacky. 
  And they all look just the same. 

Input

  The input has several test cases. The first line contains the integer t (1 ≤ t ≤ 10) which is the total number of test cases. 
  For each test case, a line contains four non-negative integers a, b, c and d where a, b, c, d ≤ 2^62, indicating the numbers of green boxes, pink boxes, blue boxes and yellow boxes. 
Output

  For each test case, output a line with the total number of boxes. 
Sample Input

  1. 4
  2. 1 2 3 4
  3. 0 0 0 0
  4. 1 0 0 0
  5. 111 222 333 404

Sample Output

  1. 10
  2. 0
  3. 1
  4. 1070

解题思路:
  测试数量t,每个测试给出四个巨大的数a,b,c,d要求计算他们的和,由于数的长度过大这里采用字符串模拟加法(好像ull也可以)。

  小学我们学过一种极为好用的方法——竖式计算

对于两个数字,将它们记录为字符串,从个位开始按位计算,记录记录完后的结果与进位,计算下一位时将进位加上即可。

AC代码

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int maxn = 1e5+;
  4. struct BigNum{ //记录大数
  5. int num[maxn];
  6. int len; //长度
  7. BigNum(){
  8. memset(num, , sizeof(num));
  9. len = ;
  10. }
  11. };
  12. BigNum change(string temp){ //将字符串转换为大数类型
  13. //为了方便计算将字符串倒过来储存
  14. BigNum a;
  15. a.len = temp.size();
  16. for(int i = ; i < a.len; i++) //逆序储存字符串
  17. a.num[i] = temp[a.len - i - ] - '';
  18. return a;
  19. }
  20. BigNum add(BigNum a, BigNum b){
  21. BigNum c;
  22. int carry = ;//进位
  23. for(int i = ; i < a.len || i < b.len; i++){//以较长的长度为界限
  24. int temp = a.num[i] + b.num[i] + carry;//两个位置相加后加上进位
  25. c.num[c.len++] = temp % ; //记录该位结果
  26. carry = temp / ; //记录进位
  27. }
  28. if(carry != ) //记录首位进位
  29. c.num[c.len++] = carry;
  30. return c;
  31. }
  32. int main()
  33. {
  34. int t;
  35. while(scanf("%d", &t) != EOF){ //输入测试数量
  36. while(t--){
  37. string temp1;
  38. BigNum sum, temp;
  39. for(int i = ; i < ; i++){
  40. cin >> temp1;
  41. temp = change(temp1); //输入大数并记录为BigNum型
  42. sum = add(sum, temp);
  43. //计算和
  44. }
  45. for(int i = sum.len - ; i >= ; i--)
  46. printf("%d",sum.num[i]);
  47. printf("\n");
  48. }
  49. }
  50. return ;
  51. }

HDU 6225 Little Boxes的更多相关文章

  1. HDU 6225.Little Boxes-大数加法 (2017ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学))

    整理代码... Little Boxes Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/O ...

  2. HDU 1475 Pushing Boxes

    Pushing Boxes Time Limit: 2000ms Memory Limit: 131072KB This problem will be judged on PKU. Original ...

  3. 2017ACM/ICPC亚洲区沈阳站(部分解题报告)

    HDU 6225 Little Boxes 题意 计算四个整数的和 解题思路 使用Java大整数 import java.math.BigInteger; import java.util.Scann ...

  4. 2017ACM/ICPC亚洲区沈阳站-重现赛

    HDU 6222 Heron and His Triangle 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6222 思路: 打表找规律+大数运算 首先我 ...

  5. HDU 5810 Balls and Boxes(盒子与球)

     Balls and Boxes(盒子与球) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/O ...

  6. HDU 5810 Balls and Boxes (找规律)

    Balls and Boxes 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...

  7. HDU 5810 Balls and Boxes 数学

    Balls and Boxes 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...

  8. hdu 4190 Distributing Ballot Boxes(贪心+二分查找)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4190 Distributing Ballot Boxes Time Limit: 20000/1000 ...

  9. hdu 4190 Distributing Ballot Boxes 二分

    Distributing Ballot Boxes Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

随机推荐

  1. Git Note - git tag

    git tag is used to create labels, usually for version numbers. Format: git tag <TagName> <r ...

  2. 调整Linux最大打开文件数

    #!/bin/bash ## 文件数限制 ulimit -n ulimit -Sn ulimit -Hn ## fs.nr_open,进程级别 ## fs.file-max,系统级别 ## 最大文件描 ...

  3. jQuery outerHeight() 方法

    outerHeight() 方法返回第一个匹配元素的外部高度. 如下面的图像所示,该方法包含 padding 和 border. 提示:如需包含 margin,请使用 outerHeight(true ...

  4. 如何创建一个自己的.NET Core Global Tools

    索引 NET Core应用框架之BitAdminCore框架应用篇系列 框架演示:https://www.bitadmincore.com 框架源码:https://github.com/chenyi ...

  5. 开源应用框架BitAdminCore:更新日志20180605

    索引 NET Core应用框架之BitAdminCore框架应用篇系列 框架演示:http://bit.bitdao.cn 框架源码:https://github.com/chenyinxin/coo ...

  6. MvvmLight框架使用入门(二)

    上一篇我们简单对MvvmLight做了介绍.罗列了三个DLL中,各个命名空间下主要类的定义及大致作用.因为只是范范的概论,对于从未接触过MvvmLight的萌新来说,根本就是在晃点他们.不过万事开头难 ...

  7. sharepoint 2013 升级要求

    1. 安装过程合理: A. 可以同时在管理中心.两台前端.搜索服务器上安装重新发布的SP1补丁包(所提供的链接) B. 等待所有SP1补丁包安装完成,依次在管理中心.两台前端.搜索服务器上运行配置向导 ...

  8. iOS错误 - too many open files (error = 24)

    碰到这个错误是在用 UIImageView 显示图片的时候.UIImage 用的是 imageNamed 方法.错误原因是打开了太多的文件.应该是太多文件的打开导致了 UIImage 的 cache ...

  9. Syncthing源码解析

    Gogland编译Syncthing 源码目录说明 Syncthing启动过程分析 在Gogland中对Syncthing的各个模块进行调试 第三方库

  10. 总结day2 ---- while循环的简单使用, 格式化输出.运算符.以及编码的应用

    内容提要 一 : while 循环 while 的基本语句操作 如何终止循环 二 :格式化输出 三 :运算符号 四 :编码初识别 一 : while 循环 1  >>>>whi ...