View Code of Problem 609

#include<iostream>
#include<cstring>
#include<algorithm>
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
	string str;
	int n;
	while(cin>>str>>n)
    {
        int len=str.length();
        int x=0;
        while(n--)
        {
            int flag=1;
            for(int i=0;i<len-1;i++)
            {
                if(str[i]>str[i+1])
                {
                    flag=0;
                    for(int j=i;j<len-1;j++)
                        str[j]=str[j+1];
                        len--;break;
                }
            }
            if(flag) len--;
        }
        while(str[x]=='0')
        {
            x++;
        }
        //cout<<"x "<<x<<"  "<<len;
        if(x>=len)
            cout<<0;
        else {
            for(int i=x;i<len;i++)
                cout<<str[i];
        }
        cout<<endl;
    }
	return 0;
}

Double click to view unformatted code.


Back to problem 609