(STL Dafa) HDU 3283

Source: Internet
Author: User

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 descriptionfor This problem, you'll write a program that takes a (possibly long) string of decimal digits, and O Utputs the permutation of those decimal digits that have the next larger value (as a decimal number)
than the input number. For example:
123
279134399742-279134423799
It is possible this no permutation of the input digits has a larger value. For example, 987.

Inputthe first line of input contains a single integer P, (1≤p≤1000), which are the number of data sets that follow. Each of the data set is a contains the data set number, followed by a space, and followed by up to the decimal digits Which is the input value.

Outputfor Each data set there are one line of output. If there is no larger permutation of the input digits, the output should being the data set number followed by a single space , followed by the string biggest. Ifthere is a solution, the output should being the data set number, a single space and the next larger
Permutation of the input digits.

Sample Input31 1232 2791343997423 987

Sample OUTPUT1 1322 2791344237993 biggest

Source2009 Greater New York Regional STL Dafa
#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\n", x,s);        else            printf ("%d biggest\n", x);    }    return 0;}

  

(STL Dafa) HDU 3283

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.