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. LUN

    1概念 LUN的全称是Logical Unit Number,也就是逻辑单元号.我们知道SCSI总线上可挂接的设备数量是有限的,一般为8个或者16个,我们可以用Target ID(也有称为SCSI I ...

  2. linux中执行java或者mvn命令提示没有权限解决办法

    $ chmod a+x /var/jenkins_home/jdk1.8.0_191/bin/java $ chmod a+x /var/jenkins_home/apache-maven-3.3.9 ...

  3. Git 安装配置,key导入

    系统 Centos 6.5 安装git 命令  yum install  git 配置git用户名 git config --global user.name "yangchengguo&q ...

  4. Sql语法高级应用之六:如何在Sql语句中如何使用TRY...CATCH

    TRY...CATCH使用范例 BEGIN TRY //逻辑语句块 END TRYBEGIN CATCH //Catch异常处理块 SET @msg = ERROR_MESSAGE(); PRINT ...

  5. Android App的破解技术有哪些?如何防止反编译?

     现在最流行的App破解技术大多是基于一定相关技术的基础:如一定阅读Java代码的能力.有一些Android基础.会使用eclipse的一些Android调试的相关工具以及了解一些smali的语法规范 ...

  6. 【题解】 UVa11210 Chinese Mahjong

    pdf传送门 直接模拟+搜索,考虑一下选哪一个是将,然后搜出顺子和刻子,最后判断一下可不可行就好了! #include<stdio.h> #include<string.h> ...

  7. Java面试题(全)--视频系列

    此系列为面试笔试题的视频讲解,以下均为超链接,点击即可进入每个知识点的讲解. Java面试题01.面试的整体流程 Java面试题02.java的垮平台原理 Java面试题03.搭建一个java的开发环 ...

  8. [bzoj4009] [HNOI2015]接水果 整体二分+扫描线+dfs序+树状数组

    Description 风见幽香非常喜欢玩一个叫做 osu!的游戏,其中她最喜欢玩的模式就是接水果. 由于她已经DT FC 了The big black, 她觉得这个游戏太简单了,于是发明了一个更 加 ...

  9. 替代iframe新逻辑

    使用ajax请求.下面是代码逻辑 $.ajax({ url:url, type:'get', dataType: "text", success:function(msg){ $( ...

  10. Elasticsearch(9):使用Logstash-input-jdbc同步数据库中的数

    1.数据同步方式 全量同步与增量同步 全量同步是指全部将数据同步到es,通常是刚建立es,第一次同步时使用.增量同步是指将后续的更新.插入记录同步到es. 2.常用的一些ES同步方法 1). elas ...