반응형

www.acmicpc.net/problem/1748

 

1748번: 수 이어 쓰기 1

첫째 줄에 N(1 ≤ N ≤ 100,000,000)이 주어진다.

www.acmicpc.net

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
using namespace std;
int n, i, ans;
int pow(int x, int n) {
    if (n == 0)
        return 1;
    return x * pow(x, n - 1);
}
int main() {
    cin >> n;
    i = 1;
    while (n >= pow(10, i)) {
        ans += 9 * pow(10, i - 1* i;
        i++;
    }
    ans += (n - pow(10, i - 1+ 1* i;
    cout << ans;
}
cs
반응형

+ Recent posts