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

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

Sample Output

10
0
1
1070

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

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

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

AC代码

 #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+;
struct BigNum{ //记录大数
int num[maxn];
int len; //长度
BigNum(){
memset(num, , sizeof(num));
len = ;
}
};
BigNum change(string temp){ //将字符串转换为大数类型
//为了方便计算将字符串倒过来储存
BigNum a;
a.len = temp.size();
for(int i = ; i < a.len; i++) //逆序储存字符串
a.num[i] = temp[a.len - i - ] - '';
return a;
}
BigNum add(BigNum a, BigNum b){
BigNum c;
int carry = ;//进位
for(int i = ; i < a.len || i < b.len; i++){//以较长的长度为界限
int temp = a.num[i] + b.num[i] + carry;//两个位置相加后加上进位
c.num[c.len++] = temp % ; //记录该位结果
carry = temp / ; //记录进位
}
if(carry != ) //记录首位进位
c.num[c.len++] = carry;
return c;
}
int main()
{
int t;
while(scanf("%d", &t) != EOF){ //输入测试数量
while(t--){
string temp1;
BigNum sum, temp;
for(int i = ; i < ; i++){
cin >> temp1;
temp = change(temp1); //输入大数并记录为BigNum型
sum = add(sum, temp);
//计算和
}
for(int i = sum.len - ; i >= ; i--)
printf("%d",sum.num[i]);
printf("\n");
}
}
return ;
}

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. AngularJs2 构建简单的英雄编辑器

    参考上一篇文章的步骤,重新把相关环境准备.目录结构走一遍. 这一次我们要开始创建真正的Angularjs项目了. 显示我们的英雄 我们要在应用中显示英雄数据 我们来为 AppComponent 添加两 ...

  2. eFrameWork学习笔记-eOleDB

    eOleDB是eFrameWork框架下基础的数据访问类,用于执行SQL语句,返回DataTable,分页,返回数据库所有库,库的所有表,表的所有列,Json导入.导出等. HTML: <div ...

  3. insert into 的另一种添加插入新行方式

    语法 1 插入一行 insert into table (field1,field2.....) select value1,value2........; 2 插入多行 insert into ta ...

  4. C#基础笔记(第十八天)

    1.HTMLHyper Text Markup Language 超文本标记语言在HTML当中存在着大量的标签,我们用HTML提供的标签,将要显示在网页中的内容包含起来.就构成了我们的网页. CSS: ...

  5. Message Loop 原理及应用

    此文已由作者王荣涛授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. Message loop,即消息循环,在不同系统或者机制下叫法也不尽相同,有被叫做event loop,也有 ...

  6. mysql--MySQL数据库的简单认识

    一.MySQL介绍 1.mysql版本 双授权版本:社区版(完全免费,功能也够nb了)和商业版(更好,功能更多更强大一些,但是收费,VIP,有售后服务,也会参考和吸收社区版的一些nb的功能,安全性和稳 ...

  7. 查看npm安装包版本

    npm list 版本号. eg: npm list socket.io

  8. [推荐] 网络侦查工具 NMAP 简单入门

    [推荐] 网络侦查工具 NMAP 简单入门 # 前言 作为一只运维开发,总是避不开要和网络打交道的.尤其是当自身能力到达瓶颈,开始从事云计算以求突破.会有搭建多台虚拟机的需要,这时候如果在手工的查询 ...

  9. IntelliJ IDEA中可以用Tab键跳出括号和引号吗?

    在 Settings->Editor->General->Smart Keys 中勾选 Jump outside closing bracket/quote with Tab 即可.

  10. XMPPFramework核心类介绍

    XMPPFramework结构 在进入下一步之前,先给大家讲讲XMPPFramework的目录结构,以便新手们更容易读懂文章.我们来看看下图: 虽然这里有很多个目录,但是我们在开发中基本只关心Core ...