Remove K words from string to make it lexographically highest
// Online C++ compiler to run C++ program online
#include <iostream>
#include <string>
using namespace std;
int remov(string str){
int min=999;
int k=0;
for (int i=0;i<str.size();i++){
if (min>str[i]){
k=i;
min=str[i];
}
}
return k;
}
int main() {
string str="zzzzzzzyyyyyyyyabc";
cout<<str;
int k=3;
while(k>0){
int idx=remov(str);
//cout<<idx<<endl;
str.erase(idx,1);
cout<<endl;
cout<<str;
k--;
}
return 0;
}
Comments
Post a Comment