题意:计算出以下一百个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. 开源分布式MySQL中间件探究与应用 dba+

  2. 介绍C++ STL常用模板使用方法的相关资料

    1.vector的几种初始化及赋值方式

  3. _DataStructure_C_Impl:求图G中从顶点u到顶点v的一条简单路径

    #pragma once #include<stdio.h> #include<stdlib.h> #define StackSize 100 typedef int Data ...

  4. eclipse+maven的web项目访问jsp乱码

    在jsp中第一行加一句这个就不会乱码了 <%@ page language="java" import="java.util.*" pageEncodin ...

  5. Centos安装FastDFS+Nginx

    一.安装环境: gcc:安装nginx需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境,需要安装gcc: yum install gcc-c++ PCRE:PCRE(Perl C ...

  6. hdoj--1257--最少拦截系统(动态规划)

    最少拦截系统 Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Submit Status ...

  7. Java-Maven:POM百科

    ylbtech-Java-Maven:POM百科 Maven是以项目为中心的设计.POM(project object model)是Maven对一个单一项目的描述.没有POM的话,Maven是毫无用 ...

  8. php 写日志函数(原创)

    function write_log($msg,$isEcho=false,$path=''){ $path?'':$path='logs'.DIRECTORY_SEPARATOR.'log'.dat ...

  9. 爬虫—分析Ajax爬取今日头条图片

    以今日头条为例分析Ajax请求抓取网页数据.本次抓取今日头条的街拍关键字对应的图片,并保存到本地 一,分析 打开今日头条主页,在搜索框中输入街拍二字,打开开发者工具,发现浏览器显示的数据不在其源码里面 ...

  10. c语言open()介绍

    2013-09-0914:40:13 1. 头文件: #include <sys/types.h> #include <sys/stat.h> #include <fcn ...