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 ...
随机推荐
- node 把base数据合成图片
var cr = new Buffer(img_Datas, 'base64'); var img = params.img_path + '/' + picDevNo + '_' + params. ...
- 在Ubuntu12.04中搭建NFS的步骤
1.首先安装nfs-kernel-server apt-get install nfs-kernel-server 2.然后创建一个目录: mkdir -p /opt/share 并赋予权限777: ...
- SAP ERP和C4C Account和Contact的双向同步
Account和Contact是C4C里唯一支持可以和ERP进行双向同步的主数据类别. C4C里创建一个Account:Mouser Electronics 在C4C里保存Account,自动同步到E ...
- 【UML】类图Class diagram(转)
http://blog.csdn.net/sds15732622190/article/details/48860711 前言 说到UML,相信大家就能立刻反应出其中的类图,为什么这么说呢,类图和用例 ...
- UVA 211 The Domino Effect 多米诺效应 (回溯)
骨牌无非两种放法,横着或竖着放,每次检查最r,c最小的没访问过的点即可.如果不能放就回溯. 最外面加一层认为已经访问过的位置,方便判断. #include<bits/stdc++.h> ; ...
- Object Modeling
https://developer.apple.com/library/content/documentation/General/Conceptual/CocoaEncyclopedia/Objec ...
- duboo 配置文件
官方文档 http://dubbo.apache.org/en-us/docs/user/quick-start.html 自己的 <?xml version="1.0" e ...
- 【转】 iOS学习之NSBundle介绍和使用
bundle是一个目录,其中包含了程序会使用到的资源.这些资源包含了如图像,声音,编译好的代码,nib文件(用户也会把bundle称为plug-in).对应bundle, cocoa提供了类NSBun ...
- java基础—线程(二)
一.线程的优先级别
- iOS或Mac开发者应该记住的前缀