首页 > 试题广场 >

#include using names...

[填空题]
#include <iostream>
using namespace std;
const int maxn = 50;
void getnext(char str[]) {
    int l = strlen(str), i, j, k, temp;
    k = l - 2;
    while (k >= 0 && str[k] > str[k + 1]) k--;
    i = k + 1;
    while (i < l && str[i] > str[k]) i++;
    temp = str[k];
    str[k] = str[i - 1];
    str[i - 1] = temp;
    for (i = l - 1; i > k; i--)
        for (j = k + 1; j < i; j++)
            if (str[j] > str[j + 1]) {
                temp = str[j];
                str[j] = str[j + 1];
                str[j + 1] = temp;
            }
    return;
}
int main( ) {
    char a[maxn];
    int n;
    cin >> a >> n;
    while (n > 0) {
        getnext(a);
        n--;
    }
    cout << a << endl;
    return 0;
}

输入:NOIP 3
输出:1

这道题你会答吗?花几分钟告诉大家答案吧!