HDU 6225 Little Boxes
Little Boxes
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的更多相关文章
- HDU 6225.Little Boxes-大数加法 (2017ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学))
整理代码... Little Boxes Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/O ...
- HDU 1475 Pushing Boxes
Pushing Boxes Time Limit: 2000ms Memory Limit: 131072KB This problem will be judged on PKU. Original ...
- 2017ACM/ICPC亚洲区沈阳站(部分解题报告)
HDU 6225 Little Boxes 题意 计算四个整数的和 解题思路 使用Java大整数 import java.math.BigInteger; import java.util.Scann ...
- 2017ACM/ICPC亚洲区沈阳站-重现赛
HDU 6222 Heron and His Triangle 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6222 思路: 打表找规律+大数运算 首先我 ...
- HDU 5810 Balls and Boxes(盒子与球)
Balls and Boxes(盒子与球) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/O ...
- HDU 5810 Balls and Boxes (找规律)
Balls and Boxes 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...
- HDU 5810 Balls and Boxes 数学
Balls and Boxes 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...
- hdu 4190 Distributing Ballot Boxes(贪心+二分查找)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4190 Distributing Ballot Boxes Time Limit: 20000/1000 ...
- hdu 4190 Distributing Ballot Boxes 二分
Distributing Ballot Boxes Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
随机推荐
- Cenots 7 Configure static IP
For example: # cd /etc/sysconfig/ifcfg-enp3s0 # cat ifcfg-enp3s0 TYPE=EthernetBOOTPROTO=staticIPADDR ...
- C++ 模板和 C# 泛型之间的区别(C# 编程指南)
C# 泛型和 C++ 模板都是用于提供参数化类型支持的语言功能. 然而,这两者之间存在许多差异. 在语法层面上,C# 泛型是实现参数化类型的更简单方法,不具有 C++ 模板的复杂性. 此外,C# 并不 ...
- StarUML3.0选择不同类型图和导出
StarUML(简称SU),是一种创建UML类图,生成类图和其他类型的统一建模语言(UML)图表的工具. 可绘制9款UML图:用例图.类图.序列图.状态图.活动图.通信图.构件图.部署图以及复合结构图 ...
- 数据库工具SQLite Expert Personal的简单使用
官方网站: sqliteexpert官方网址 - SQLite administration | SQLite Expert 先使用SQLite Expert Personal熟悉SQLite语句 插 ...
- docker pull manifest unknown blob errors
问题:docker pull manifest unknown blob errors 原因:公司网络是代理模式,所以我的 docker 服务配置成proxy模式: [root@localhost ~ ...
- ClamAV学习【7】——病毒库文件格式学习
搜查到一份详细的ClamAV病毒文件格式资料(http://download.csdn.net/detail/betabin/4215909),英文版,国内这资料不多的感觉. 重点看了下有关PE的病毒 ...
- sql server中的 trimtrailingblanks
使用sp_help 查出 发现有个这个属性, 如何修改呢? SET ANSI_PADDING ONAlter Table Sys_users_History Alter column PveSit ...
- J - Judge(快速幂)(同余定理)
J - Judge Time Limit:1000MS Memory Limit:131072KB 64bit IO Format:%lld & %llu Submit S ...
- 洛谷P1393 动态逆序对(CDQ分治)
传送门 题解 听别人说这是洛谷用户的双倍经验啊……然而根本没有感觉到……因为另外的那题我是用树状数组套主席树做的……而且莫名其妙感觉那种方法思路更清晰(虽然码量稍稍大了那么一点点)……感谢Candy大 ...
- ObjectARX动态添加AutoCAD传统下拉菜单入门篇(一)
ObjectARX动态添加传统下拉菜单入门篇 图文by edata , 转载注明出处 http://www.cnblogs.com/edata AutoCAD 添加传统下拉菜单有很多种方式,比较典型 ...