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

暴力
#include<stdio.h>
#include<string>
#include<string.h>
#include<algorithm>
#include<iostream>
typedef long long ll;
using namespace std;
int T, s, len;
char ch[1010];
int main()
{
cin >> T;
while (T--)
{
cin >> s >> ch;
len = strlen(ch);
for (int i = 0; i < len; i++)
{
if (s <= 0)break;
char max = '0';
int key;
for (int j = i + 1; j < len && j <= i + s; j++)//找到能移动的最大位数
{
if (max < ch[j])
{
max = ch[j];
key = j;
}
}
if (max > ch[i])
{
for (int j = key; j > i; j--)
ch[j] = ch[j - 1];
ch[i] = max, s =s-( key - i);
}
}
cout << ch << endl;
}
return 0;
}
/**********************************************************************
Problem: 1270
User: leo6033
Language: C++
Result: AC
Time:12 ms
Memory:2024 kb
**********************************************************************/

CSUOJ 1270 Swap Digits的更多相关文章

  1. 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. 奇怪的C代码

    ; int ans = (++i)+(++i)+(++i); ans等于多少?我想大多数同学都会和我一样的认为: ans = 4 + 5 + 6 = 15. 而实际结果呢? - Linux下用gcc编 ...

  2. 微服务深入浅出(11)-- SpringBoot整合Docker

    添加Dockerfile 在目录src/main/resources目录下店家Dockerfile文件: From java MAINTAINER "Eric"<eric.l ...

  3. HDU 1719 Friend 规律题

    解题报告:规定数字1和数字2是Friend number,然后规定,若a和b是Friend number,那么a*b+a+b也是Friend number,输入一个数,让你判断这个数是否是Friend ...

  4. sql server 查询本年的每个月的数据

    一.以一行数据的形式,显示本年的12月的数据,本示例以2017年为例,根据CreateDate字段判断,计算总和,查询语句如下: end) as '1月', end) as '2月', end) as ...

  5. Kissy && Require

    KISSY add(name?,factory?,deps)  函数挂载在全局对象KISSY上,用来定义模块.   一个 JS 文件包含一个add()(这时路径+文件名可以用作模块名),如果一个文件包 ...

  6. aarch64_g1

    GAPDoc-1.5.1-12.fc26.noarch.rpm 2017-02-14 07:37 1.0M fedora Mirroring Project GAPDoc-latex-1.5.1-12 ...

  7. java 多线程 Future callable

    面向对象5大设计原则 1.单一职责原则  一个类只包含它相关的方法,增删改查.一个方法只包含单一的功能,增加.一个类最多包含10个方法,一个方法最多50行,一个类最多500行.重复的代码进行封装,Do ...

  8. Jmeter运行结果unicode编码乱码问题

    一.web页面乱码 比如访问百度返回页面显示乱码,如下会有问号 如果想让他显示中文可以按以下操作: 1.打开jmter配置文件 bin/jmeter.properties 2.修改配置文件,查找“sa ...

  9. Luogu P1160 【队列安排】

    详细的链表讲解 很明显的一个链表裸题 和普通的链表有一个区别就是这个题 可以O(1)插入,O(1)查询 然后我们为了方便,采用双向链表,定义s.f作为指针数组 更详细的解释见代码 #include&l ...

  10. Oracle约束

    1.非空约束 DROP TABLE member PURGE; CREATE TABLE member( mid NUMBER, name ) NOT NULL ); 2.唯一约束 DROP TABL ...