Project Euler 13 Large sum
题意:计算出以下一百个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的更多相关文章
- Project Euler 345: Matrix Sum
题目 思路: 将问题转化成最小费用流 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #incl ...
- Python练习题 041:Project Euler 013:求和、取前10位数值
本题来自 Project Euler 第13题:https://projecteuler.net/problem=13 # Project Euler: Problem 13: Large sum # ...
- Python练习题 034:Project Euler 006:和平方与平方和之差
本题来自 Project Euler 第6题:https://projecteuler.net/problem=6 # Project Euler: Problem 6: Sum square dif ...
- 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 ...
- (Problem 13)Large sum
Work out the first ten digits of the sum of the following one-hundred 50-digit numbers. 371072875339 ...
- Python练习题 036:Project Euler 008:1000位数字中相邻13个数字最大的乘积
本题来自 Project Euler 第8题:https://projecteuler.net/problem=8 # Project Euler: Problem 8: Largest produc ...
- Python练习题 030:Project Euler 002:偶数斐波那契数之和
本题来自 Project Euler 第2题:https://projecteuler.net/problem=2 # Each new term in the Fibonacci sequence ...
- Python练习题 029:Project Euler 001:3和5的倍数
开始做 Project Euler 的练习题.网站上总共有565题,真是个大题库啊! # Project Euler, Problem 1: Multiples of 3 and 5 # If we ...
- 【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 × ...
随机推荐
- js setTimeout函数
最近在看JS DOM编程艺术,在第十章的动画里面有个setTimeout函数的例子中涉及了很多的引号,研究了好大一会才看明白,综合网上各个大神的解释和自己的理解,其原理是这样的: 首先看下程序源代码: ...
- 1010针对一个binlog日志的分析
针对一个BINLOG日志的分析 -- 当前binlog_format | ROW[root@109 mysql]# cat wang1010.txt/*!50530 SET @@SESSION.PSE ...
- 神经网络入门游戏推荐BugBrain
今天看到一款神经网络入门游戏.BugBrain.在游戏中,你能够通过连接神经元.设置神经元阈值等建造虫子的大脑,让瓢虫.蠕虫.蚂蚁等完毕各种任务.下载下来玩了玩,难度真不是入门级的= =! 真心佩服作 ...
- [React] Refactor componentWillReceiveProps() to getDerivedStateFromProps() in React 16.3
The componentWillReceiveProps() method is being deprecated in future version of React (17). Many of ...
- rsync与cwRsync
以下这个链接是windows之间的csRsync和csRsyncServer同步教程: http://www.cnblogs.com/wwufengg/p/rsync-config.html !Att ...
- linux中udev简单的用法【转】
本文转载自:http://blog.csdn.net/qq_29729577/article/details/50825134 udev是Linux提供的一种在用户态管理设备的一种机制,udev的详细 ...
- MongoDB如何实现读写分离
MongoDB如何实现读写分离 MongoDB复制集(Replica Set)通过存储多份数据副本来保证数据的高可靠,通过自动的主备切换机制来保证服务的高可用.但需要注意的时,连接副本集的姿势如果不对 ...
- 第8章 MyBatis简介
# 创建一个名称为mybatis的数据库 CREATE DATABASE mybatis; # 使用名称为mybatis的数据库 USE mybatis; # 创建一个tb_user表,有id.nam ...
- NOIP2013 D1T3 货车运输
[NOIP2013T3]货车运输 背景 noip2013day1 描述 A 国有 n 座城市,编号从 1 到 n,城市之间有 m 条双向道路.每一条道路对车辆都有重 量限制,简称限重.现在有 q 辆货 ...
- BZOJ4517: [Sdoi2016]排列计数(组合数+错位排列)
Time Limit: 60 Sec Memory Limit: 128 MBSubmit: 1626 Solved: 994[Submit][Status][Discuss] Descripti ...