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
output
input
output
思路:对每一个数字进行判断,如果>=5就更新,注意第一个数字的特殊处理
AC代码如下:
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; }
相关文章推荐
- 学习使用crosswalk
- python基础:搜索路径
- [Unity2d系列教程] 002.引用外部DLL - C
- Python中的static method、class method和instance method
- windows环境下安装及使用redis
- 端到端与点到点的区别
- LeetCode_66. Plus One_数组加一
- Java学习第8天(5):面向对象-继承-接口
- android启动 uboot启动 rom制作
- Scala implicit
- AndroidManifest.xml 文件详解
- 用UIColloctionView 实现cell放大以及无限轮播
- 读书笔记--互联网必读《长尾理论》作者克里斯.安德森
- 手机端META详细解释
- 定时任务 - quartz
- 前端总结(设计向)
- java 获取当前时间月加1 ,年加1
- iOS 保持界面流畅的技巧
- str_replace中的匹配空白符,必须用双引号
- 给 Android 开发者的 RxJava 详解