P1106 delete several issues

Title Description

A keyboard input precision positive integer N N (not more than 250 2 . 5 0), to remove any of k remaining about the order of the original digital k digits to form a new positive integer. Programming of a given N N and K K, to find a solution so that the remaining digits of the new minimum number.

Input Format

n- n-(highly accurate positive integer)

k k (the number of digits to be deleted)

Output Format

The last remaining minimum number.

Sample input and output

Input # 1
175438 
4
Output # 1
13

 

#include<bits/stdc++.h>
using namespace std;
int a[251],b[251],i,j,q,t=1,k,n,l,m=0,x=0,y=1,u=0;
string num;
int main(){
    cin>>num>>l;
    n=num.length();
    int o=l;
    k=n-l;
    for(i=1;i<=n;++i)
	{
		a[i]=num[i-1]-'0';
		b[i]=9;
	}
	while(a[y]==0)
	{
		y++;
	}
	for(i=y;i<=n;i++)
	{
		if(a[i]!=0)
		m++;
		if(a[i]==0)
		{
			
			if(m<=l)
			{
			l-=m;
			u+=m;
			m=0;
			t=i;
				
			}
			else break;
		}
	}
		while(a[t]==0)
	{
		t++;
	}
	int kk=n-t+1-o+u;
	if(kk<=0)
	cout<<0;
    else{
    	for(int j=1;j<=kk;j++)
	{
	for(i=t;i<=n;i++)
	{
		if(a[i]==0&&n-i+1>=kk-j+1)
		{
			b[j]=0;
			t=i+1;
			break;
		}
		if(a[i]<b[j]&&n-i+1>=kk-j+1)
		{
			b[j]=a[i];
			t=i+1;
		}
	}}
	for(i=1;i<=kk;i++)
	{
		cout<<b[i];
	}

	}
    	
}

  

Guess you like

Origin www.cnblogs.com/lau1997/p/12589710.html