https://www.luogu.com.cn/problem/P1106
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
template<typename DataType>
DataType qmi(DataType m, int k)
{
DataType res = 1, t = m;
while (k)
{
if (k&1) res = res * t;
t = t * t;
k >>= 1;
}
return res;
}
int read(){
int x = 0,f = 1;
char c = getchar();
while (c<'0'||c>'9') {
if (c=='-') {
f = -1;
}
c = getchar();
}
while (c>='0'&&c<='9') {
x = x*10+c-'0';
c = getchar();
}
return x*f;
}
#define fi(a,b) for(int i = a; i <= b; i++)
#define fj(a,b) for(int j = a; j >= b; j--)
struct MAP{
int pos;
int data;
};
void quickSort(MAP *a,int left,int right){
int i,j;
MAP temp,t;
temp = a[(left+right)/2];//基准值
i = left;
j = right;
while(i<=j){
while (a[j].data > temp.data) {
j--;
}
while (a[i].data < temp.data) {
i++;
}
if (i<=j) {
t = a[i];
a[i] = a[j];
a[j] = t;
//继续下一步
i++;
j--;
}
}
if(left<j)quickSort(a,left, j);//继续分治
if(i<right)quickSort(a,i, right);//继续分治
}
//const int maxNum = 255;
//MAP num[maxNum];
//MAP num1[maxNum];
int n,k,a[257],rest,t=1,minp,cnt=0;
bool flag = 0;
string num;
int main(){
cin>>num>>k;
n = num.length();
for(int i = 1; i <= n ; ++i){
a[i]=num[i-1]-'0';
}
rest = n-k;
while(cnt < rest){
minp = t;//最大值的位置
for(int i = t; i <= k+t; ++i){//寻找最大值的位置
if(a[minp] > a[i])minp = i;
}
if(a[minp])
flag=1;
if(flag)
cout<<a[minp];
k -= (minp-t);
t = minp+1;
cnt++;
}
if(!flag)cout<<0;
return 0;
}
/*
175438
4
============
13
*/
网友评论