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 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.

Sample test(s)
Input
27
Output
22
Input
4545
Output
4444


题意:给一个数字x,比较x的每一位m与9-m的大小,取较小的那一位替换原来的位,最高位不能为0,输出这个最小数;
分析:给出数据已超过int范围改用longlong,如果数据更大考虑用字符串,同时数组存储每一位,注意最高位不能为0;

 1 #include<cstring>
 2 #include<cstdio>
 3 #include<iostream>
 4 
 5 using namespace std;  6  7 int main()  8 {  9 long long n; 10 int a[20],j=0; 11 cin>>n; 12 for(;n!=0;n/=10) 13  { 14 int m=n%10; 15 if(n/10!=0&&9-m<m) m=9-m; 16 else if(n/10==0&&m!=9&&9-m<m) m=9-m; 17 a[j++]=m; 18  } 19 for(j--;j>=0;j--) 20 cout<<a[j]; 21 cout<<endl; 22 }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值