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. javaSe数据类型

    在学完了java程序的结构以及注释后呢按照一般的教程我们应该学点什么呢?   没错就是变量和数据类型[其实我的内心是拒绝的,又是无聊的一大堆,不仅无聊,还得掌握] 好了首先介绍什么是变量: 变量:变量 ...

  2. POJ 1845 Sumdiv (数学,乘法逆元)

    题意: 给出数字A和B,要求AB的所有因子(包括AB和1)之和 mod 9901 的结果. 思路: 即使知道公式也得推算一阵子. 很容易知道,先把分解得到,那么得到,那么的所有因子之和的表达式如下: ...

  3. POJ Charlie's Change 查理之转换(多重背包,变形)

    题意: 给定身上的4种硬币,分别是1 ,5 ,10, 25面额各有多张,要求组成面额p的硬币尽可能多.输出组成p的4种硬币各自的数量. 思路: 多重背包,300+ms.用01背包+二进制的方法.记录下 ...

  4. UWP开发:应用设置存储

    应用设置储存指的是保存在应用程序储存区中的键/值对的字典集合,它自动负责序列化对象,并将其保存在应用程序里.以键/值对方式提供一种快速数据访问的方式,主要用于储存一些应用信息. 1,简介 应用设置是W ...

  5. HDU 5451 Best Solver(fibonacci)

    感谢这道题让我复习了一遍线代,还学习了一些奇奇怪怪的数论. 令 二项展开以后根号部分抵消了 显然有 所以要求的答案是 如果n比较小的话,可以直接对二项式快速幂,但是这题n很大 这个问题和矩阵的特征值以 ...

  6. targetcli save error

    iscsi configuration unable to save python error “ValueError: 'Implict and Explict' is not in list” / ...

  7. jsp页面之间传值 以及如何取出url的参数

    写项目时往往要写多个页面,而多个jsp之间传值有时是必要的,这时可以用到如下方法: 而在另一个页面取值可以用:${param.xxx}   此处的xxx就是要传递的值

  8. Bootstrap历练实例:标签页内的下拉菜单

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...

  9. 01_1_Socket实现

    01_1_Socket实现 1.什么是MIME Multipurpos Internet Mail Extension 指明白传送内容的格式 最早用于邮件附件 2.HTTP协议基础 HTTP(Hype ...

  10. iOS调用WebService接口

    首先有几点说在前面 一般,在请求URL的后面带有WSDL字样的需要调用WebService URL样式例子:http://ip:port/navigable/webservice/loginSeric ...