今天木有好好复习……还有20天考试……心里还是挺慌的……
好吧~这道题蛋碎,考英语~
嗯……本来我在笨笨的一点一点写……直到我膝盖中了一箭,觉得这样写下去实在是太二逼了……算了~上网简单看一下。
还是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……真是不爽……