博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
选修课网址 1088: The Owl and the Fox
阅读量:4049 次
发布时间:2019-05-25

本文共 2184 字,大约阅读时间需要 7 分钟。

1088: The Owl and the Fox
Time Limit: 5 Sec  Memory Limit: 128 MB
Submit: 44  Solved: 14
[Submit][Status][Web Board]
Description
Fox Mithra has finally learned the numbers and he is now familiar with the concept of ‘one’, ’two’, ‘three’ and also even ‘zero’, ‘minus one’, ‘minus two’ and so on. Really, an achievement for such a small fox. He took the textbook and copied the integers from the book one by one from the smallest to the biggest on the wall of his enclosure in the ZOO.
“Look, there is something wrong with your sequence on the wall”, said the owl who just landed on the branch above Mithra’s head. “You should put 30 between 20 and 22, there.”
“Why?”
“Because the importance of a number is judged by the sum of its digits. 30 is therefore less important than 22 and it is more important than 20. And obviously, 30 should be equally close to 20 and 22 because its sum of digits differs only by one from both 20 and 22.”
“I see,” replied Mithra, “you are really clever. Can you help me please to rearrange the sequence correctly? Each time I tell you a number N you will tell me the closest smaller number with sum of digits less by one than the sum of digits of N.”
“With pleasure,” nodded the owl majestically.
Your task is to imitate the owl’s task. Given an integer N you have to find the biggest integer
which is smaller than N with sum of digits less by one than the sum of digits of N. 
Input
There are more test cases. Each case consists of a line containing a single integer N (1 ≤ N ≤ 100 000). The input is terminated by a line containing string “END” and no other symbols. 
Output
For each test case print on a separate line the number demanded by fox Mithra. 
Sample Input
30
199
1000
1520
END
Sample Output
20
198
0
1510
HINT

Source

容易超时  用字符char数组会快一点

#include
#include
#include
using namespace std;int main(){ char a[1000010]; long long n,m,i,k; ios::sync_with_stdio(false); while(scanf("%s",a)&&strcmp(a,"END")) { n=strlen(a); n=n-1; k=5; for(i=n;i>=0;i--) { if(a[i]!='0') { a[i]=a[i]-1; if(i!=0) { break; } } if(a[0]=='0') { k=0; } } if(k==0)printf("0\n"); else printf("%s\n",a); } return 0;}

转载地址:http://xtfci.baihongyu.com/

你可能感兴趣的文章
coursesa课程 Python 3 programming course_2_assessment_7 多参数函数练习题
查看>>
coursesa课程 Python 3 programming course_2_assessment_8 sorted练习题
查看>>
在unity中建立最小的shader(Minimal Shader)
查看>>
1.3 Debugging of Shaders (调试着色器)
查看>>
关于phpcms中模块_tag.class.php中的pc_tag()方法的含义
查看>>
vsftp 配置具有匿名登录也有系统用户登录,系统用户有管理权限,匿名只有下载权限。
查看>>
linux安装usb wifi接收器
查看>>
多线程使用随机函数需要注意的一点
查看>>
getpeername,getsockname
查看>>
让我做你的下一行Code
查看>>
浅析:setsockopt()改善程序的健壮性
查看>>
关于对象赋值及返回临时对象过程中的构造与析构
查看>>
VS 2005 CRT函数的安全性增强版本
查看>>
SQL 多表联合查询
查看>>
Visual Studio 2010:C++0x新特性
查看>>
drwtsn32.exe和adplus.vbs进行dump文件抓取
查看>>
cppcheck c++静态代码检查
查看>>
在C++中使用Lua
查看>>
一些socket的编程经验
查看>>
socket编程中select的使用
查看>>