题库 信息学奥赛题库 题目列表 NOIP2009年普及组阅读程序填写结果题:#include ...
填空题

NOIP2009年普及组阅读程序填写结果题:

#include <iostream>
usingnamespacestd;
constint 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;
    return0;
}

输入:NOIP 3 

输出:___

题目信息
阅读程序 2009年 初赛
-
正确率
0
评论
111
点击