Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

PS 부수기

Project Euler #17 : 1부터 1000까지 영어로 썼을 때 사용된 글자의 개수는? 본문

Project Euler

Project Euler #17 : 1부터 1000까지 영어로 썼을 때 사용된 글자의 개수는?

jyheo98 2020. 8. 7. 12:45
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int main() {
    VI a = { -1,3,3,5,4,4,3,5,5,4 }; // one ~ nine
    VI b = { -1,3,6,6,8,8,7,7,9,8,8,6 }; // ten ~ twenty
    VI c = { -1,3,6,6,5,5,5,7,6,6 }; // ten ~ ninety
    int ans = 0// 1-99
    for(int i=1 ; i<=9 ; i++) ans += a[i];
    for(int i=10 ; i<=20 ; i++) ans += b[i-9];
    for(int i=21 ; i<=99 ; i++) {
        ans += c[i / 10];
        if (i % 10 != 0) ans += a[i % 10];
    }
    int ANS = ans;
    for(int i=1 ; i<=9 ; i++) {
        ANS += 100 * a[i] + 100 * 10 + ans;
        ANS -= 3
    }
    ANS += 11;
    cout << ANS;
}
cs

Forty 스펠 fourty인줄알고 개뻘짓함.

Comments