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
- (514A)codeforce
- codeforce 514A
- Codeforce A
- Codeforce # A Plug-in
- codeforce 2A Winner
- Contest on codeforce A
- codeforce 11 04 A
- codeforce小水题--A. Presents
- Codeforce #145A Cinema
- codeforce日记 371A
- CodeForce 393A Nineteen
- codeforce 402A - Nuts
- Codeforce A. Milking cows
- codeforce 427A
- codeforce 433A
- codeforce 6A
- codeforce 7A
- codeforce 9A
- 实现状态栏全沉浸以及兼容低版本半透明沉浸
- 信息融合(Informationsfusion)-前言
- 学习数据库必须掌握的54条SQL查询语句
- SDH、MSTP、OTN和PTN的区别和联系
- 判断二维平面上两线段是否相交
- codeforce 514A
- LeetCode : Regular Expression Matching DFS/动态规划
- 多维数组和指针
- Java语言 instanceof关键字
- Manacher算法------求最长回文子串(Java)
- LeetCode Maximum Subarray 通俗讲解解法的背后原理
- Android RecyclerView简单入门学习
- Sqoop 初识
- 牛客网 | 删除链表中重复的结点