Pasha Maximizes

B. Pasha Maximizes
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Pasha has a positive integer a without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.

Help Pasha count the maximum number he can get if he has the time to make at most k swaps.

Input

The single line contains two integers a and k (1 ≤ a ≤ 1018; 0 ≤ k ≤ 100).

Output

Print the maximum number that Pasha can get if he makes at most k swaps.

1|0输入输出样例

输入 #1
1990 1
输出 #1
9190
输入 #2
300 0
输出 #2
300
输入 #3
1034 2
输出 #3
3104
输入 #4
9090000078001234 6
输出 #4
9907000008001234
复制代码
#include<bits/stdc++.h> using namespace std; const int N=1e5+10; string s; int res,n,num,cnt,i; int main() { cin>>s>>n; num=n; while(num>0){ while(s[cnt]=='9'&&cnt<=s.size()) ++cnt; int maxx=cnt; if(cnt>=s.size()) break; for(i=cnt+1;i<=num+cnt&&i<s.size();i++) if(s[maxx]<s[i]) maxx=i; if(maxx==cnt){//如果后面没有比它大的了,那就找下一位 cnt++; continue; } for(i=cnt+1;i<=maxx;i++) swap(s[cnt],s[i]),num--;//每一步都要交换 } cout<<s<<endl; return 0; }
复制代码

 


__EOF__

本文作者Sakurajimamai
本文链接https://www.cnblogs.com/o-Sakurajimamai-o/p/17474840.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   o-Sakurajimamai-o  阅读(9)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
-- --
点击右上角即可分享
微信分享提示