您的位置:首页 > 其它

Codeforces 514A Chewbaсca and Number

2016-01-21 16:22 513 查看
A. Chewbaсca and Number

time limit per test
1 second

memory limit per test
256 megabytes

input
standard input

output
standard output

Luke Skywalker gave Chewbacca an integer number x. Chewbacca isn't good at numbers but he loves inverting digits in them.
Inverting digit tmeans 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.

Sample test(s)

input
27


output
22


input
4545


output
4444


思路:对每一个数字进行判断,如果>=5就更新,注意第一个数字的特殊处理
AC代码如下:
#include <iostream>
#include <cstring>
using namespace std;

int main(){

    char x[20];
    int ok=1;
    while(cin>>x){
        int len=strlen(x);
        for(int i=0;i<len;i++){
            if(i==0){
                if(x[i]=='9')
                    cout<<x[i];
                else if(x[i]>='5')
                    cout<<'9'-x[i];
                else cout<<x[i];
            }
            else {
                if(x[i]>='5')
                    cout<<'9'-x[i];
                else cout<<x[i];
            }
        }
        cout<<endl;

    }
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: