4168: Same Digits 

Time Limit(Common/Java):1000MS/3000MS     Memory Limit:65536KByte
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的更多相关文章

  1. [LeetCode] Reconstruct Original Digits from English 从英文中重建数字

    Given a non-empty string containing an out-of-order English representation of digits 0-9, output the ...

  2. [LeetCode] Remove K Digits 去掉K位数字

    Given a non-negative integer num represented as a string, remove k digits from the number so that th ...

  3. [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数

    Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...

  4. [LeetCode] Add Digits 加数字

    Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. ...

  5. LeetCode 258. Add Digits

    Problem: Given a non-negative integer num, repeatedly add all its digits until the result has only o ...

  6. ACM: FZU 2105 Digits Count - 位运算的线段树【黑科技福利】

     FZU 2105  Digits Count Time Limit:10000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  7. Revolving Digits[EXKMP]

    Revolving Digits Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. 【LeetCode】Add Digits

    Add Digits Given a non-negative integer num, repeatedly add all its digits until the result has only ...

  9. 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 ...

随机推荐

  1. 查询日志logcat使用总结

    cmd命令行中使用adb logcat命令查看Android系统和应用的log,dos窗口按ctrl+c中断输出log记录.logcat日志中的优先级/tag标记: android输出的每一条日志都有 ...

  2. sql优化实战:从1353秒到135秒(删除索引+修改数据+重建索引)

    最近在优化日结存储过程,日结存储过程中大概包含了20多个存储过程. 发现其有一个存储过程代码有问题,进一步发现结存的数据中有一个 日期字段business_date 是有问题的,这个字段对应的类型是v ...

  3. 生成gt数据出问题

    使用cout打印uchar类型数据时,打印出来是其相应的ascii码

  4. java static block

    java 中 静态块的作用 (一)java 静态代码块 静态方法区别一般情况下,如果有些代码必须在项目启动的时候就执行的时候,需要使用静态代码块,这种代码是主动执行的;需要在项目启动的时候就初始化,在 ...

  5. 实验1 c语言最基本内容

    part 1 验证性内容 总结:经受了数组和结构体的双重折磨后,发现这部分好简单...现在没啥问题了... part  2  补全程序 1.判断奇偶 // 程序功能: // 要求用户从键盘输入一个整数 ...

  6. Silverlight日记:动态操作Grid

    一,动态生成Grid public static Grid CreateGrid(List<T_METER> List) { var g = new Grid(); if (null == ...

  7. Windows系统安装docker

    下载安装包 官网 点击 Get Started ,打开入门页面,往下拉,找到 Download for Windows 打开 下载页面 ,点击 Please Login To Download ,要注 ...

  8. 119. Pascal's Triangle II@python

    Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle. Note t ...

  9. [BZOJ] 1441 Min

    题意:给一堆数ai,求S=Σxiai,使得S最小且为正整数 根据裴蜀定理,一定存在ax+by=gcd(a,b),同理可以推广到n个整数 也就是说,在不考虑正负的情况下,所有数的gcd就是所求 #inc ...

  10. k8s的高级调度方式

    默认的scheduler的调度过程:1.预选策略:从所有节点当中选择基本符合选择条件的节点.2.优选函数:在众多符合基本条件的节点中使用优选函数,计算节点各自的得分,通过比较进行排序.3.从最高得分的 ...