Description

Now we have a number, you can swap any two adjacent digits of it, but you can not swap more than K times. Then, what is the largest probable number that we can get after your swapping?

Input

There is an integer T (1 <= T <= 200) in the first line, means there are T test cases in total.

For each test case, there is an integer K (0 <= K < 106) in the first line, which has the same meaning as above. And the number is in the next line. It has at most 1000 digits, and will not start with 0.

There are at most 10 test cases that satisfy the number of digits is larger than 100.

Output

For each test case, you should print the largest probable number that we can get after your swapping.

Sample Input

3
2
1234
4
1234
1
4321

Sample Output

3124
4213
4321

Hint


Submit Page
#include<iostream>
#include<cstdio>
#include<cmath>
#include<set>
#include<string>
#include<algorithm>
using namespace std; int main()
{
ios::sync_with_stdio(false);
int T,k;
string str;
cin>>T;
while(T--)
{
int temp=0;
cin>>k>>str;
while(k)
{
int Max=str[temp]-'0',flag=temp;
int pos=temp+k>str.length() ? str.length()-1 : temp+k;
for(int i=temp+1;i<=pos;i++)
{
if(str[i]-'0'>Max) Max=str[i]-'0',flag=i;
}
k-=flag-temp;
//cout<<flag<<endl; int ff=str[flag]-'0';
for(int i=flag-1;i>=temp;i--)
str[i+1]=str[i];
str[temp]=ff+'0';
temp++;
if(temp>=str.length()) break;
// cout<<k<<endl;
}
cout<<str<<endl;
} return 0;
}
/**********************************************************************
Problem: 1270
User: song_hai_lei
Language: C++
Result: AC
Time:12 ms
Memory:2180 kb
**********************************************************************/


Swap Digits的更多相关文章

  1. CSUOJ 1270 Swap Digits

    Description ) in the first line, which has the same meaning as above. And the number is in the next ...

  2. Maximum Swap LT670

    Given a non-negative integer, you could swap two digits at most once to get the maximum valued numbe ...

  3. leetcode 学习心得 (4)

    645. Set Mismatch The set S originally contains numbers from 1 to n. But unfortunately, due to the d ...

  4. Educational Codeforces Round 75 (Rated for Div. 2) C. Minimize The Integer

    链接: https://codeforces.com/contest/1251/problem/C 题意: You are given a huge integer a consisting of n ...

  5. Codeforce 1251C. Minimize The Integer

    C. Minimize The Integer time limit per test2 seconds memory limit per test256 megabytes inputstandar ...

  6. SZU:A66 Plastic Digits

    Description There is a company that makes plastic digits which are primarily put on the front door o ...

  7. 交换基本数据类型的方法swap,并影响到主方法

    不知道朋友在哪里看到的问题,qq来问我,题目是:在不修改主方法的前提下使用一个方法交换两个int的值,方法如下: public static void main(String[] args) { In ...

  8. [LeetCode] Maximum Swap 最大置换

    Given a non-negative integer, you could swap two digits at most once to get the maximum valued numbe ...

  9. [Swift]LeetCode670. 最大交换 | Maximum Swap

    Given a non-negative integer, you could swap two digits at most once to get the maximum valued numbe ...

随机推荐

  1. 手把手教你用netty撸一个ZkClient

    原文地址: https://juejin.im/post/5dd296c0e51d4508182449a6 前言 有这个想法的缘由是前一阵子突发奇想, 想尝试能不能直接利用js连接到zookeeper ...

  2. ThinkPHP v5.1.x POP 链分析

    环境:MacOS 10.13 MAMAP Prophp 7.0.33 + xdebugVisual Studio Code前言我所理解的 POP Chain:利用魔术方法并巧妙构造特殊属性调用一系列函 ...

  3. HTML中的表格标签

      表格是网页制作中使用最多的工具之一,在制作网页时,使用表格可以更清晰地排列数据.但是在实际制作过程中,表格更多用在网页布局的定位上.很多网页都是以表格布局的.这是因为表格在文本和图像的位置控制方面 ...

  4. Lab8:文件系统

    文件系统的概念 文件系统是操作系统中管理持久性数据的子系统,提供数据存储和访问功能 文件是具有符号名,由字节序列构成的数据项集合 文件系统的功能 分配文件磁盘空间 管理文件块(位置和顺序) 管理空闲空 ...

  5. [转发]CSR 量产 烧录 软件

    蓝牙量产软件主要是为了应对蓝牙设备在批量生产时的一些如固件下载,地址下载,名字修改,以及一些辅助测试和检验功能. 目前,CSR推出的蓝牙芯片按照存储介质以及可编程与否分为两大类:ROM版本和Flash ...

  6. 数据类型转换&运算符

    基本数据类型注意事项 整型类型:long>int>short>byte java默认类型为int型 long a = 123 表示将int类型的数值赋给更大范围的long类型,当数据 ...

  7. Jmeter---第一天配置中文环境、安装jmeter插件

    一:安装就不在赘述,百度有很多优秀的文章.接下来开始我自己的学习笔记 二:设置JMETER,切换中文环境. 首先打开jmeter的安装目录,找到bin文件目录中的jmeter.propertie 打开 ...

  8. JavaWeb01-常识

    软件系统体系结构 1        常见软件系统体系结构B/S.C/S 1.1 C/S l  C/S结构即客户端/服务器(Client/Server),例如QQ: l  需要编写服务器端程序,以及客户 ...

  9. 18063-圈中的游戏-(第九章第4题)-"数组指针的使用"-数学分析

    代码借鉴CSDN大佬https://blog.csdn.net/weixin_41409140/article/details/88071047(对大佬的大佬代码进行分析) 18063 圈中的游戏 时 ...

  10. Android状态栏兼容4.4.4与5.0,Android5.0状态栏由半透明设置为全透明

    //判断android 版本然后设置Systembar颜色 public void initSystemBar() { Window window = getWindow(); //4.4版本及以上 ...