Description

Input

Output

Sample Input

2
1432 2
4321 2

Sample Output

4312
4321

Data Constraint

.
.
.
.
.
.
.
.

分析


.
.
.
.
.
.
.
.
.

程序:
var
t,i,j,k,h,r,l,max:longint;
n:char;
s,zfc:string;
begin
    assign(input,'swap.in');
    reset(input);
    assign(output,'swap.out');
    rewrite(output);
    readln(t);
    for r:=1 to t do
    begin
        readln(zfc);
        val(copy(zfc,pos(' ',zfc)+1,length(zfc)-pos(' ',zfc)),k,j);
        delete(zfc,pos(' ',zfc),length(zfc)-pos(' ',zfc)+1);
        l:=length(zfc);
        s:=zfc;
        for i:=1 to l do
        begin
            if k=0 then break;
            max:=0;h:=0;
            for j:=i+1 to l do
            if (ord(s[j])-ord('0')>max)and(i+k>=j) then
            begin
                max:=ord(s[j])-ord('0');
                h:=j;
            end;
            if (max>ord(s[i])-ord('0')) then
            begin
                n:=s[h];
                for j:=h-1 downto i do
                begin
                    s[j+1]:=s[j];
                    dec(k);
                end;
                s[i]:=n;
            end;
        end;
        writeln(s);
    end;
    close(input);
    close(output);
end.

优质内容筛选与推荐>>
1、CString.Format的详细用法(转)
2、使用IDEA + maven 开发SpringMVC网站 (二)框架配置
3、MySQL基础数据类型
4、Math Expression API
5、android打电话的小程序


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号