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. HTTP1.0工作原理

    1.HTTP工作原理 <HTTP响应报文与工作原理详解>讲的比较详细了. 2.示例 (1)server端程序如下: package org.yeyouluo.demo.jsp; impor ...

  2. Python3+Selenium3+webdriver学习笔记7(选择多链接的结果、iframe、下拉框)

    #!/usr/bin/env python# -*- coding:utf-8 -*- from selenium import webdriverfrom selenium.webdriver.co ...

  3. ADO.Net——增、删、改、查

    数据访问 对应命名空间:System.Data.SqlClient; SqlConnection:连接对象 SqlCommand:命令对象 SqlDataReader:读取器对象 CommandTex ...

  4. pc端常见布局---水平居中布局 单元素定宽

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  5. groupmod - 修 改 群 组

    总览 SYNOPSIS groupmod [-g gid [-o]] [-n group_name ] group 描述 DESCRIPTION groupmod 命 令 会 参 照 你 命 令 列 ...

  6. C++容器类-list

    C++ 表(List容器类) 一.概念 头文件:#include <list> 又叫链表,是一种双线性链表,只能顺序访问(从前往后或从后往前) 他不支持随机访问. 二.方法 #includ ...

  7. alibaba druid监控页面的使用配置

    一.Maven中添加Durid连接池依赖 <!-- druid连接池 --> <dependency> <groupId>com.alibaba</group ...

  8. Maven搭建Struts2+Spring3+Hibernate4框架

    做了三年多的JavaEE开发了,在平时的JavaEE开发中,为了能够用最快的速度开发项目,一般都会选择使用Struts2,SpringMVC,Spring,Hibernate,MyBatis这些开源框 ...

  9. GTA5(侠盗猎车5)中文版破解版

    )中文版破解版迅雷下载地址(使用迅雷新建任务填上地址): magnet:?xt=urn:btih:65F16B126D8A656E4FC825DE204EBFAF04B070FC

  10. Github使用技巧总结

    <config> PyCharm与GitHub配置使用总结 <readme> 在github的readme添加图片 github readme写法 GitHub上README. ...