题意:计算出以下一百个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. 0807再整理SQL执行流程

    转自http://www.cnblogs.com/annsshadow/p/5037667.html MySQL架构总览->查询执行流程->SQL解析顺序   前言: 一直是想知道一条SQ ...

  2. 输入url发生了什么--前端所有知识

    面试经常会问到的一个问题,这个问题舒展开来,其实包含了前端(一些后端)几乎所有的知识.梳理一下,备忘.包含了一些面经中常问的问题. 有时间待续

  3. redis之Hash存储与String存储内存消耗对照

    存储对象User String存储方式: SET media:1155315 939 GET media:1155315 > 939 String结构存储该对象 User243 243600 存 ...

  4. Errors occurred during the build. Errors running builder &#39;Integrated External Tool Builder&#39; on proje

    Errors occurred during the build. Errors running builder 'Integrated External Tool Builder' on proje ...

  5. wpf Listbox 设置ItemContainerStyle后,ItemTemplateSelector不能触发

    解决方案: 将Listbox 的ItemTemplateSelector 改为 ItemContainerStyle中ContentPresenter ContentTemplateSelector ...

  6. usb键鼠驱动分析【钻】

    本文转载自:http://blog.csdn.net/orz415678659/article/details/9197859 一.鼠标 Linux下的usb鼠标驱动在/drivers/hid/usb ...

  7. linux中udev简单的用法【转】

    本文转载自:http://blog.csdn.net/qq_29729577/article/details/50825134 udev是Linux提供的一种在用户态管理设备的一种机制,udev的详细 ...

  8. JavaScript --晋级--优

    https://zhuanlan.zhihu.com/p/23412169 总计划 JavaScript 教程       http://www.w3school.com.cn/js/ JavaScr ...

  9. redis 学习笔记-cluster集群搭建

    一.下载最新版redis 编译 目前最新版是3.0.7,下载地址:http://www.redis.io/download 编译很简单,一个make命令即可,不清楚的同学,可参考我之前的笔记: red ...

  10. oracle11g安装与拆卸

    Oracle 11g安装 1.解压下载的包,然后进入包内,点击setup.exe开始安装 . 2.出现如下:一般把那个小对勾取消,点击下一步进行, 弹出下图这个后点'是' 3.下图后,选择创建和配置数 ...