题意:计算出以下一百个50位数的和的前十位数字。


/*************************************************************************
> File Name: euler013.c
> Author: WArobot
> Blog: http://www.cnblogs.com/WArobot/
> Created Time: 2017年06月25日 星期日 10时55分56秒
************************************************************************/ #include <stdio.h>
#include <inttypes.h>
#include <string.h> #define max(a,b) ((a) > (b) ? (a) : (b)) int32_t main() {
char s[55];
int32_t ans[5010] = {0};
for(int32_t t = 0 ; t < 100 ; t++){
scanf("%s",s);
int32_t len = strlen(s);
ans[0] = max( ans[0] , len ); // ans[0]记录最大位数
for(int32_t i = len-1 ; i >= 0 ; i--){ // 倒序加到ans[]里
ans[ len - i ] += s[i] - '0';
}
}
for(int32_t i = 1 ; i <= ans[0] ; i++){
if( ans[i] >= 10 ){ // 控制进位
ans[ i + 1 ] += ans[i] / 10;
ans[i] %= 10;
if( ans[0] < i + 1 ) ans[0] = i + 1;
}
}
for(int32_t i = ans[0] ; i >= ans[0] - 9 ; i--){
printf("%d",ans[i]);
}
puts("");
return 0;
}

Project Euler 13 Large sum的更多相关文章

  1. Project Euler 345: Matrix Sum

    题目 思路: 将问题转化成最小费用流 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #incl ...

  2. Python练习题 041:Project Euler 013:求和、取前10位数值

    本题来自 Project Euler 第13题:https://projecteuler.net/problem=13 # Project Euler: Problem 13: Large sum # ...

  3. Python练习题 034:Project Euler 006:和平方与平方和之差

    本题来自 Project Euler 第6题:https://projecteuler.net/problem=6 # Project Euler: Problem 6: Sum square dif ...

  4. Project Euler 44: Find the smallest pair of pentagonal numbers whose sum and difference is pentagonal.

    In Problem 42 we dealt with triangular problems, in Problem 44 of Project Euler we deal with pentago ...

  5. (Problem 13)Large sum

    Work out the first ten digits of the sum of the following one-hundred 50-digit numbers. 371072875339 ...

  6. Python练习题 036:Project Euler 008:1000位数字中相邻13个数字最大的乘积

    本题来自 Project Euler 第8题:https://projecteuler.net/problem=8 # Project Euler: Problem 8: Largest produc ...

  7. Python练习题 030:Project Euler 002:偶数斐波那契数之和

    本题来自 Project Euler 第2题:https://projecteuler.net/problem=2 # Each new term in the Fibonacci sequence ...

  8. Python练习题 029:Project Euler 001:3和5的倍数

    开始做 Project Euler 的练习题.网站上总共有565题,真是个大题库啊! # Project Euler, Problem 1: Multiples of 3 and 5 # If we ...

  9. 【Project Euler 8】Largest product in a series

    题目要求是: The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × ...

随机推荐

  1. LightOJ - 1231 - Coin Change (I)

    先上题目: 1231 - Coin Change (I)   PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit:  ...

  2. 【ACM】hdu_1862_EXCEL排序_201308091948

    EXCEL排序 Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  3. POJ 2008

    这道题,说实话,细节很多.不过,我没想到,光细节就能搞死人了... 参考了http://www.cppblog.com/varg-vikernes/archive/2010/03/12/109559. ...

  4. HDU 3389

    对于这道题,我们需要从(A+B)%3==0这式子考虑.对于第一条式子,我们可以知道,只能是奇偶盒子交替转移. 由第二条式子可知,要么是同余为0的A,B之间转移,要么是余数为1,2之间的 转移.后来仔细 ...

  5. redis(四))——多实例化——实现主从配置

    引言 redis是一个key-value存储系统. 和Memcached类似,它支持存储的value类型相对很多其它,包含string(字符串).list(链表).set(集合)和zset(有序集合) ...

  6. 寒武纪芯片——有自己的SDK,支持tf、caffe、MXNet

    寒武纪芯片 产品中心>智能处理器IP 智能处理器IP MLU智能芯片 软件开发环境 Cambricon-1A 高性能硬件架构及软件支持兼容Caffe.Tensorflow.MXnet等主流AI开 ...

  7. The Triangle--nyoj 18

    The Triangle 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 (Figure 1) Figure ...

  8. php打马赛克

    本文实例讲述了php实现图片局部打马赛克的方法.分享给大家供大家参考.具体分析如下: 原理: 对图片中选定区域的每一像素,增加若干宽度及高度,生成矩型.而每一像素的矩型重叠在一起,就形成了马赛克效果. ...

  9. java中 抽象类和抽象方法

    在面向对象中,所有的对象都是由类来描绘的,但是并不是所有的类都用来描绘对象的,当一个类并不能包含完整的信息来描绘一个具体的对象时,我们把这个类称为抽象类.抽象类除了不完整的描述一个对象之外,其他的功能 ...

  10. JDBC基础02

    今日知识 1. sql注入问题2. jdbc批处理3. 事务 SQL注入问题解决 1.什么是sql注入. * 用户通过相关的特殊关键字sql语句非法访问数据库 *例如: Xxx(' or '1'='1 ...