uva424高精度

<h1><center><table bgcolor="#0060F0"><tbody><tr><td><strong><span style="font-size:24px;color:#C0FFFF;"> <a target=_blank name="SECTION0001000000000000000000">Integer Inquiry</a></span> </strong></td></tr></tbody></table></center></h1><p>One of the first users of BIT's new supercomputer was Chip Diller. Heextended his explorationof powers of 3 to go from 0 to 333 and he explored taking various sumsof those numbers.</p><p>``This supercomputer is great,'' remarked Chip. ``I only wish Timothy werehere to see theseresults.'' (Chip moved to a new apartment, once one became available onthe third floor of theLemon Sky apartments on Third Street.)</p><p></p><h2><span style="color:#0070E8;"><a target=_blank name="SECTION0001001000000000000000">Input</a></span></h2><p>The input will consist of at most 100 lines of text, each of whichcontains a single VeryLongInteger.Each VeryLongInteger will be 100 or fewer characters in length, and willonly contain digits (no VeryLongInteger will be negative).</p><p></p><p>The final input line will contain a single zero on a line by itself.</p><p></p><h2><span style="color:#0070E8;"><a target=_blank name="SECTION0001002000000000000000">Output</a></span></h2><p>Your program should output the sum of the VeryLongIntegers given in the input.</p><p></p><h2><span style="color:#0070E8;"><a target=_blank name="SECTION0001003000000000000000">Sample Input</a></span></h2><p></p><pre>123456789012345678901234567890
123456789012345678901234567890
123456789012345678901234567890
0

Sample Output

370370367037037036703703703670

一大串数字的相加
用字符串接收
在转成int型
进一








#include <stdio.h>#include <string.h>#define N 110char num[N];int res[N], dig[N];int tsf(){int len = strlen(num);for (int i = 0, j = len - 1; i < len; i++, j--)dig[i] = num[j] - '0';}int main(){int s = 0;memset(res, 0, sizeof(res));while (scanf("%s", &num) && num[0] != '0') {memset(dig, 0, sizeof(dig));tsf();for (int i = 0; i < N; i++) {s += res[i] + dig[i];res[i] = s % 10;s /= 10;}}int n = N;while (res[n] == 0)n--;for (int i = n; i >= 0; i--)printf("%d", res[i]);printf("\n");return 0;}
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值