codeforce 514A

来源:互联网 发布:级联删除sql语句 编辑:程序博客网 时间:2024/05/22 16:39

题目

A. Chewbaсca and Number

LukeSkywalker 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

题意

将数字中每位数(整型 int)的数组可以转化为 9 - t。
但是第一位不能为0 而且要尽可能的小,
输出这个最小数

思路

用数组读入数字的每一位(%1d);
如果大于5 小于9 就用9 - t
如果等于9 且不是第一位 就用9 - t
如果是第一位且数字是9 不做处理
然后正序输出数组中的每一项
\n

实现方法

以下为核心部分

getchar() // 读取换行符
gets(a)
x = strlen (a);
b[i] = a[i] - ‘0’;
遍历 i

if(b [i] >= 5 && b[i] < 9)
b[i] = 9 - b[i];
if(i == 1 && b[i] = 9)
;
if(i != 1 && b[i] = 9)
b[i] = 9 - b[i];
printf

0 0
原创粉丝点击