zoukankan      html  css  js  c++  java
  • (STL大法) hdu 3283

    The Next Permutation

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 850    Accepted Submission(s): 597


    Problem Description
    For this problem, you will write a program that takes a (possibly long) string of decimal digits, and outputs the permutation of those decimal digits that has the next larger value (as a decimal number)
    than the input number. For example:
    123 -> 132
    279134399742 -> 279134423799
    It is possible that no permutation of the input digits has a larger value. For example, 987.
     
    Input
    The first line of input contains a single integer P, (1 ≤ P ≤ 1000), which is the number of data sets that follow. Each data set is a single line that contains the data set number, followed by a space, followed by up to 80 decimal digits which is the input value.
     
    Output
    For each data set there is one line of output. If there is no larger permutation of the input digits, the output should be the data set number followed by a single space, followed by the string BIGGEST. Ifthere is a solution, the output should be the data set number, a single space and the next larger
    permutation of the input digits.
     
    Sample Input
    3 1 123 2 279134399742 3 987
     
    Sample Output
    1 132 2 279134423799 3 BIGGEST
     
    Source
     
     
    STL大法
     
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<cmath>
    #include<cstdlib>
    #include<algorithm>
    #include<queue>
    #include<vector>
    #include<stack>
    #include<set>
    #include<map>
    using namespace std;
    char s[81];
    int main()
    {
        int tt,x;
        scanf("%d",&tt);
        while(tt--)
        {
            scanf("%d %s",&x,s);
            int len=strlen(s);
            if(next_permutation(s,s+len))
                printf("%d %s
    ",x,s);
            else
                printf("%d BIGGEST
    ",x);
        }
        return 0;
    }
    

      

  • 相关阅读:
    event事件学习小节
    简单的碰壁反弹效果
    从全局中通过class类名获取标签
    js中常用的Tab切换
    将一串字符串转变为驼峰样式(字符串练习)
    js控住DOM实现发布微博简单效果
    使用js制作一般网站首页图片轮播效果
    使用js实现带有停顿效果的图片滚动(按钮控制)
    js实现标准无缝滚动
    toLowerCase和toLocaleLowerCase的区别
  • 原文地址:https://www.cnblogs.com/water-full/p/4485963.html
Copyright © 2011-2022 走看看