본문 바로가기
프로그래밍/문제풀이

[etc] 백준 16676 근우의 다이어리 꾸미기

by 하용권 2019. 1. 24.

https://www.acmicpc.net/problem/16676



처음 제출 했을 때, 0인 경우를 생각 못해서 틀렸습니다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <cstdlib>
using namespace std;
 
int main(){
    int n,chk_n;
    string s_chk_n;
    
    cin >> n;
    
    string s = to_string(n);
    
    
    int size = s.size();
    for(int i = 0; i < size; i++)
        s_chk_n+='1';
    chk_n = atoi(s_chk_n.c_str());    
 
    if(n>=chk_n) cout << size;
    else if(n == 0cout << 1;
    else         cout << size-1;
}
cs


반응형