Problem Solving/BOJ

[Silver 3] 1748번 수 이어 쓰기 1

kmkunk 2022. 4. 1. 14:27
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int len = String.valueOf(n).length();
        String s = "";
        int ans = 0;

        for(int i=1; i<len; i++) {
            s += "9";
            ans += 9*Math.pow(10, i-1)*i;
        }
        
        int nine = len==1 ? 0 : Integer.parseInt(s);
        ans += (n-nine)*len;
        
        System.out.println(ans);
    }
}