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 × ...
随机推荐
- JavaScript向window onload添加加载函数
有时候我们需要在页面加载事件后完成一些函数操作,对于函数比较多的情况下可以写一个统一的加载函数 .本函数来自于JavaScript DOM 编程艺术: function addLoadEvent(fu ...
- SQL优化(SQL TUNING)之10分钟完毕亿级数据量性能优化(SQL调优)
前几天.一个用户研发QQ找我,例如以下: 自由的海豚. 16:12:01 岛主,我的一条SQL查不出来结果,能帮我看看不? 兰花岛主 16:12:10 多久不出结果? 自由的海豚 16:12:17 多 ...
- hadoop-2.6.0集群开发环境配置
hadoop-2.6.0集群开发环境配置 一.环境说明 1.1安装环境说明 本例中,操作系统为CentOS 6.6, JDK版本号为JDK 1.7,Hadoop版本号为Apache Hadoop 2. ...
- cocos2d-android学习四 ---- 精灵的创建
上篇文章我们创建了一个黑乎乎的界面.以下我们就给它增加一个精灵. 我们这次就一起来学习精灵的基础知识. 1.什么是精灵 游戏中全部会动的对象都是精灵,能够是主人公,背景元素,一个子弹或者是敌人. 一个 ...
- hdu1209(Clock)
pid=1209">点击打开hdu1209 Problem Description There is an analog clock with two hands: an hour h ...
- 用python阐释工作量证明(proof of work)
了解比特币的都知道挖矿非常耗电,这是由于比特币用到了工作量证明. 工作量证明是指系统为达到某目标而设置的工作度量方法.一開始是用在网络攻防上,大大提高攻击者的计算量,攻击成本也就上去了. 工作量证明须 ...
- springmvc之@Controller、@RequestMapping等注解解说
首先来看下一段代码: @Controller @RequestMapping("/user") public class UsersController { @RequestMap ...
- nyoj--92--图像有用区域(模拟)
图像有用区域 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 "ACKing"同学以前做一个图像处理的项目时,遇到了一个问题,他需要摘取出图片中某个黑 ...
- Elasticsearch之cur查询索引
前提, Elasticsearch之curl创建索引库 Elasticsearch之curl创建索引 Elasticsearch之curl创建索引库和索引时注意事项 Elasticsearch之cur ...
- Android 解决toolbar标题不显示问题
问题原因:toolbar的兼容性有问题 解决办法: setSupportActionBar(toolbar); toolbar使用步骤: 1.编写menu.xml 为了保持兼容需要这样写: andro ...