본문 바로가기

코드포스

[코드포스 Practice7] C. Chewbaсca and Number

Luke Skywalker gave Chewbacca an integer number x. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit t means replacing it with digit 9 - t.

Help Chewbacca to transform the initial number x to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero.

 

Input

The first line contains a single integer x (1 ≤ x ≤ 1018) — the number that Luke Skywalker gave to Chewbacca.

Output

Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes.


 

ㅋㅋ

혼란의 문제였음

 

처음에는 아 문자열 시작이 0이 되면 안되는구나 그럼 맨 앞자리 빼고 다 뒤집어야지 하다가 Wrong answer 떠서 ???거리고. 생각해보니 이거 말고 또 최소로 만들 수 있는 방법이 있었다. 999인거 앞의 두자리 0으로 바꾸고 마지막꺼만 남기면 시작이 0이 아니고 최소가 됨.. 캬 이렇게 하면 완벽하다 하고 제출했는데 계속 롱 엔숴,,, 그러다 끝났다. 

 

 

지금 확인해보니 시작이 0이 되면 안된다는 조건을 내가 잘못 이해한 것 같다. 

나는 문자열로 받아서 아 이게 0123 이러면 안 되는구나!라고 받아들였는데 문제는 자리수가 고정돼있고 맨 처음 수가 0이 되면 안된다.. 이런 뜻인듯

 

아 그럼 완전 쉽잖아ㅋㅋㅋ

 

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <string>
 
using namespace std;
using i64 = long long;
 
int main() {
    string s;
    string result = "";
    
    cin >> s;
    
    
    for(int i = 0; i < s.size(); i++){
        if(i == 0){
            if(s[i] == '9'){
                result += s[i];
                continue;
            }
        }
        
        int tmp = s[i] - '0';
        
        if(tmp >= 5)
            result += 9 - tmp + '0';
        else
            result += tmp + '0';
    }
    
    cout << result;
    
    return 0;
}

 

쬐끔 허무..