Project Euler 17
2012-11-06 22:46
281 查看
今天木有好好复习……还有20天考试……心里还是挺慌的……
好吧~这道题蛋碎,考英语~
嗯……本来我在笨笨的一点一点写……直到我膝盖中了一箭,觉得这样写下去实在是太二逼了……算了~上网简单看一下。
还是jason大牛的……
写的简洁明了啊~
哎……自愧不如……
我的上来了……
突然想到……其实我以前文章都可以加上pe的标签啊……啊……还可以把题目复制上,找到翻译的……复制上……提高人气啊……
算了……
最后赞美一个~sublime真的太好用了!!!不过用着别人的key……真是不爽……
好吧~这道题蛋碎,考英语~
嗯……本来我在笨笨的一点一点写……直到我膝盖中了一箭,觉得这样写下去实在是太二逼了……算了~上网简单看一下。
还是jason大牛的……
import time start = time.time() S = [0,3,3,5,4,4,3,5,5,4,3,6,6,8,8,7,7,9,8,8] D = [0,3,6,6,5,5,5,7,6,6] H = 7 T = 8 total = 0 for i in range(1,1000): c = i % 10 # singles digit b = ((i % 100) - c) / 10 # tens digit a = ((i % 1000) - (b * 10) - c) / 100 # hundreds digit if a != 0: total += S[a] + H # "S[a] hundred if b != 0 or c != 0: total += 3 # "and" if b == 0 or b == 1: total += S[b * 10 + c] else: total += D[b] + S[c] total += S[1] + T elapsed = time.time() - start print "%s found in %s seconds" % (total,elapsed)
写的简洁明了啊~
哎……自愧不如……
我的上来了……
#include<stdio.h> //one to nineteen int S[20] = {0,3,3,5,4,4,3,5,5,4,3, 6,6,8,8,7,7,9,8,8}; //twenty thirdty .... int D[10] = {0,0,6,6,5,5,5,7,6,6}; //hundred int H = 7; //thousand int T = 8; //and int N = 3; int main(){ int i, a, b, c; int sum = 0; for (i=1; i<1000; i++){ c = i%10; b = ((i%100) - c)/10; a = i/100; // greater than 100 if (a != 0){ sum +=S[a] + H; if (b != 0 || c != 0){ sum += N; } } // [1 to 19] if (b == 0 || b == 1){ sum += S[b*10 + c]; } else{ //[20 to 99] sum += D[b] + S[c]; } } //add one thousand sum += S[1] + T; printf("%d", sum); }带了些许的注释~咩~
突然想到……其实我以前文章都可以加上pe的标签啊……啊……还可以把题目复制上,找到翻译的……复制上……提高人气啊……
算了……
最后赞美一个~sublime真的太好用了!!!不过用着别人的key……真是不爽……
相关文章推荐
- Project Euler – Problem 17
- Project Euler: Problem 17 Number letter counts
- [Project Euler]加入欧拉 Problem 17
- project euler 17 Number letter counts
- [Project Euler] Problem 17
- 【Project Euler】1 第一题
- 疯狂Spring Cloud连载(17)Hystrix属性配置与回退
- C语言及程序设计提高例程-17 一维数组的定义和引用
- 17上海市网络安全大赛wp【web】
- [leetcode] 17 Letter Combinations of a Phone Number
- 6-17 Shortest Path [2](25 point(s))(dijkstra)
- 6-17复数四则运算
- ubuntu16.04 安装Clion 16和17版的破解服务器地址
- .NET设计模式(17):命令模式(Command Pattern)(转)
- 数据结构与算法分析(Java语言描述)(17)—— 二叉搜索树的深度优先与广度优先遍历
- 17.如何自学Struts2之Struts2 Annotation注释[视频]
- 文档总结17-C语言基础
- oracle优化17
- Advanced Programming in UNIX Environment Episode 17
- Linux Mint 17 + 小米WIFI创建手机热点