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 ...
随机推荐
- Tempdb--monitoring and troubleshooting
TempDB用来存放临时表.全局临时表.表变量以及排序或HASH等操作引发的中间结果集 TempDB在每次实例重启时重新创建,TempDB数据库文件的初始化大小取决于Model数据库的文件大小或显示A ...
- .NET控件名称缩写一览表
转载自如下链接: https://www.cnblogs.com/xpvincent/p/9334851.html 字体实在是太小了,我看着好闹心,就复制过来自己放大下,谢谢. 标准控件1 btn B ...
- vue 路由传参
mode:路由的形式 用的哪种路由 1.hash 路由 会带#号的哈希值 默认是hash路由 2.history路由 不会带#的 单页面开发首屏加载慢怎么解决?单页面开发首屏加载白屏怎 ...
- css编写规范最佳实践
最初,在编写CSS的时候,我们往往想到哪儿就写到哪儿,它们之间的关联性和有序性并不在考虑之中.但随着代码量的增加,亦或是多人共同开发,CSS的编写规范变得重要起来了.本文通过三个方面,总结出CSS编写 ...
- [Swift实际操作]七、常见概念-(14)使用UIColor设置界面组件的颜色属性
打开移动应用程序,不可避免的需要和颜色打交道.本文将为你演示颜色对象的使用. 首先导入需要使用到的界面工具框架 import UIKit 通过UIColor的属性,可以获得橙色.右侧的实时反馈区,显示 ...
- 把序列中的N个元素赋值给多个变量
说明: python中序列和散列 序列:可通过偏移量来进行切片的对象.列表.元组.字符串都属于序列. 散列:无法通过偏移量来进行切片的对象.比如 集合.字典 一. 变量的数量跟序列元素的个数一样 1. ...
- Markdown入门简介
参考 http://sspai.com/25137 作者: Te_Lee 文章来源: 少数派 Markdown入门简介(使用工具Haroopad) 一.使用的工具----haroopad(http:/ ...
- jenkins详解(一)
还是以以下几个问题来学习这个软件: 1.jenkins是什么? 2.为什么要用jenkins? 3.怎么用jenkins? 1.jenkins是什么? Jenkins是一个开源的.提供友好操作界面的持 ...
- docker微服务部署之:五、利用DockerMaven插件自动构建镜像
docker微服务部署之:四.安装docker.docker中安装mysql和jdk1.8.手动构建镜像.部署项目 在上一篇文章中,我们是手动构建镜像,即: 4.1.2.5.1.2.6.1.2中的将d ...
- AFNetworking 3.1.0 使用中某些知识点讲解
# POST / GET 请求 /*! 首先要知道,POST请求不能被缓存,只有 GET 请求能被缓存.因为从数学的角度来讲,GET 的结果是 幂等 的,就好像字典里的 key 与 value 就是 ...