TOJ4168: Same Digits
4168: Same Digits 
Total Submit: 115 Accepted:62
Description
Your program will be given an integer X. Find the smallest number larger than X consisting of the same digits as X.
Input
The first line of input contains the integer X (1 ≤ X ≤ 999 999).
The first digit in X will not be a zero.
Output
Output the result on a single line. If there is no such number, output 0.
Sample Input
156
Sample Output
165
这个前缀为0没有什么卵用
贪心去实现,是不是存在,就看他后面是不是有比他大的
然后找到最新奥德那个数交换后直接sort
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
char s[];
gets(s);
int n=strlen(s),i,j;
for(i=n-; i>; i--)
if (s[i]>s[i-])break;
if(!i)puts("");
else
{
int x=s[i-],f=i;
for (j=i+; j<n; j++)
if(s[j]>x&&s[j]<s[f])f=j;
swap(s[f], s[i-]);
sort(s+i,s+n);
puts(s);
}
return ;
}
TOJ4168: Same Digits的更多相关文章
- [LeetCode] Reconstruct Original Digits from English 从英文中重建数字
Given a non-empty string containing an out-of-order English representation of digits 0-9, output the ...
- [LeetCode] Remove K Digits 去掉K位数字
Given a non-negative integer num represented as a string, remove k digits from the number so that th ...
- [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...
- [LeetCode] Add Digits 加数字
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. ...
- LeetCode 258. Add Digits
Problem: Given a non-negative integer num, repeatedly add all its digits until the result has only o ...
- ACM: FZU 2105 Digits Count - 位运算的线段树【黑科技福利】
FZU 2105 Digits Count Time Limit:10000MS Memory Limit:262144KB 64bit IO Format:%I64d & ...
- Revolving Digits[EXKMP]
Revolving Digits Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 【LeetCode】Add Digits
Add Digits Given a non-negative integer num, repeatedly add all its digits until the result has only ...
- Add Digits, Maximum Depth of BinaryTree, Search for a Range, Single Number,Find the Difference
最近做的题记录下. 258. Add Digits Given a non-negative integer num, repeatedly add all its digits until the ...
随机推荐
- Layer:如何调用layer.open打开的的iframe窗口中的JS?
layer.open({type: 2,content: 'test/iframe.html',success: function(layero, index){ var body = layer.g ...
- 深入理解Java流机制(一)
一.前言 C语言本身没有输入输出语句,而是调用"stdio.h"库中的输入输出函数来实现.同样,C++语言本身也没有输入输出,不过有别于C语言,C++有一个面向对象的I/O流类库& ...
- 第一篇Active Directory疑难解答概述(2)
从故障诊断的角度来看,无论用户对象存在于哪个Active Directory域中,Exchange都需要访问此数据.这意味着所有包含启用Exchange的对象的域必须对其运行Setup / Prepa ...
- Python+selenium之获取验证信息
通常获取验证信息用得最多的几种验证信息分别是title,URL和text.text方法用于获取标签对之间的文本信息. 代码如下: from selenium import webdriverimpor ...
- python_92_面向对象初体验
class dog: def __init__(self,name): self.name=name def bulk(self): print('%s汪汪汪!'%self.name) d1=dog( ...
- OO作业第三单元总结
目录 一.JML语言理论基础及应用工具链 二.部署JMLUnitNG,自动生成测试用例 三.架构设计 第一次作业 第二次作业 第三次作业 四.Bug分析 五.心得体会 一.JML语言理论基础及应用工具 ...
- 抓取oracle建表语句及获取建表ddl语句
抓取oracle建表语句及获取建表ddl语句 1.抓取代码如下: 1.1.产生表的语法资料 DECLARE-- v_notPartTable VARCHAR2(1000):= '&2'; -- ...
- 使用vs2013打开VS2015的工程文件的解决方案(适用于大多数vs低版本打开高版本)
前言:重装系统前我使用的是vs2015(有点装*),由于使用2015实在在班上太另类了, 导致我想在其他同学的vs下看一看我写的代码都无法达成! 而且最关键的是交作业的时候,老师的2013也没有办法打 ...
- 通过luac编译lua脚本
在lua官网下载一个lua的release包,里面有已经编译好的lua启动文件(包括lua.exe),其中还有luac.exe, 这个程序是用来将lua文件编译成二进制码, 使用方法很简单,在控制台调 ...
- JavaScript递归实现对象深拷贝
let personOne = { name:"张三", age:18, sex:"male", children:{ first:{ name:"z ...