题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1047

题目意思:就是求大整数加法。有多个案例,每个案例之间要输出一个空格。

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; const int maxn = + ;
char t[maxn];
int s[maxn], ans[maxn]; int main()
{
int l1, l2, n, i, j, l, len, num;
scanf("%d", &n);
while (n--)
{
num = ;
memset(ans, , sizeof(ans));
while (cin >> t && strcmp(t, ""))
{
memset(s, , sizeof(s));
l1 = strlen(t);
for (i = ; i < l1; i++)
s[i] = t[l1-i-] - '';
num++;
if (num == )
{
for (i = ; i < l1; i++)
ans[i] = s[i];
l2 = l1;
}
else
{
len = max(l1, l2); // l1:s[i] l2:ans[i]
l = min(l1, l2);
int sum, c = ;
for (i = ; i < len; i++)
{
if (i < l)
{
sum = s[i] + ans[i] + c;
ans[i] = sum % ;
c = (sum > ? : );
}
else
{
if (l1 == len)
sum = s[i] + c;
else
sum = ans[i] + c;
ans[i] = sum % ;
c = (sum > ? : );
}
}
if (c == && i == len)
{
ans[len] = ;
l2 = len + ;
}
else
l2 = len; // 关键之处!!!!之前不记得更新错了好多次!!!
}
}
if (!num)
printf("");
else
{
for (i = maxn-; i >= ; i--)
{
if (ans[i])
break;
}
for ( ; i >= ; i--)
printf("%d", ans[i]);
}
printf("\n");
if (n)
cout << endl;
}
return ;
}

  忽略格式问题,借鉴了别人的写法

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; const int maxn = 1e5 + ;
char t[maxn];
int num[maxn]; void add(char s[])
{
int z = ;
int len = strlen(s);
for (int i = len-; i >= ; i--)
{
num[z] += (s[i] - '');
num[z+] += num[z] / ;
num[z] %= ;
z++;
}
} int main()
{
int i, ok = ;
memset(num, , sizeof(num));
while (scanf("%s", t) != EOF && strcmp(t, ""))
add(t);
for (i = maxn; i >= ; i--)
{
if (num[i])
{
ok = ;
break;
}
}
for ( ; i >= && ok; i--)
printf("%d", num[i]);
if (!ok)
printf("");
printf("\n");
return ;
}

hdu Integer Inquiry 解题报告的更多相关文章

  1. 【LeetCode】397. Integer Replacement 解题报告(Python)

    [LeetCode]397. Integer Replacement 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/inte ...

  2. 【LeetCode】343. Integer Break 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 数学解法 动态规划 日期 题目地址:https:// ...

  3. Bestcoder13 1003.Find Sequence(hdu 5064) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5064 题目意思:给出n个数:a1, a2, ..., an,然后需要从中找出一个最长的序列 b1, b ...

  4. hdu 1896.Stones 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1896 题目意思:给出 n 块石头的初始位置和能到达的距离.对于第奇数次遇到的石头才抛掷,偶数次的就忽略 ...

  5. Valentine's Day Round 1001.Ferries Wheel(hdu 5174)解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5174 题目意思:给出 n 个人坐的缆车值,假设有 k 个缆车,缆车值 A[i] 需要满足:A[i−1] ...

  6. BestCoder27 1001.Jump and Jump... (hdu 5162) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5162 题目意思:有 n 个 kid,每个 kid 有三个成绩 a, b, c.选最大的一个成绩作为这个 ...

  7. BestCoder27 1002.Taking Bus(hdu 5163) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5163 题目意思:有 n 个车站,给出相邻两个车站的距离,即车站 i 和车站 i+1 的距离为 di ( ...

  8. BestCoder25 1001.Harry and Magical Computer(hdu 5154) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5154 题目意思:有 n 门 processes(编号依次为1,2,...,n),然后给出 m 种关系: ...

  9. BestCoder14 1002.Harry And Dig Machine(hdu 5067) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5067 题目意思:给出一个 n * m 的方格,每一个小方格(大小为1*1)的值要么为 0 要么为一个正 ...

随机推荐

  1. eclipse 五种断点

    1. Line BreakpointLine Breakpoin是最简单的Eclipse断点,只要双击某行代码对应的左侧栏,就对该行设置上断点. 2. WatchpointLine Breakpoin ...

  2. Java线程池的内部实现

    一.线程池介绍 线程是稀缺资源,如果无限制的创建,不仅会消耗系统资源,还会降低系统的稳定性,合理的使用线程池可以对线程进行统一的分配.调优和监控,并有以下好处: (1)降低资源消耗. (2)提高响应速 ...

  3. Parameter Binding in ASP.NET Web API #Reprinted

    http://www.asp.net/web-api/overview/formats-and-model-binding/parameter-binding-in-aspnet-web-api

  4. layer的alert、prompt等操作如何响应键盘的回车和ESC操作

    layer.prompt({title: '请输入数据', formType: 1, //隐藏用户输入内容 // 这个是确定按钮的事件 "success":function(){ ...

  5. app后端开发系列文章文件夹

    一点废话 每个程序猿心中,都有一个大牛梦.我们在晨曦之光中敲击着代码,在寒冬覆雪中思考着0与1. 夏练三伏 冬练三九这说的就是我们这群[江湖]中人.在这里我们门派林立,C语言派历史悠久,在程序界就是嵩 ...

  6. G 全然背包

    <span style="color:#3333ff;">/* /* _________________________________________________ ...

  7. 百度地图SDK调试SDKInitializer.initialize(getApplicationContext())错误

    首先描写叙述下问题出现的原因.開始的时候写了一个百度地图SDK的demo来试功能,由于最開始用的是Eclipse自带的AVD来调试,一切正常. 都能够正常验证,可是由于受不了重复的重新启动AVD设备, ...

  8. iOS 摇一摇的实现

    - (void)viewDidLoad { [super viewDidLoad]; [[UIApplication sharedApplication] setApplicationSupports ...

  9. 笔记本POWER部分的应用——(MOS/LDO/BUCK BOOST)

    一.MOSFET 简介: 金属-氧化物半导体场效应晶体管,简称金氧半场效晶体管(Metal-Oxide-Semiconductor Field-Effect Transistor, MOSFET)是一 ...

  10. A20 Gate信号

    https://doc.docsou.com/ba8e6b0612d6a989b7cebeaae-5.html Gate A20 Option 功能:设置A20 地址线的控制模式 设定值:Fast 或 ...