FZU 1853 Number Deletion

本文介绍了一道算法题目,要求编写程序通过删除指定数量的数字来获得最小可能的正整数,同时处理好可能产生的前导零问题。文章提供了一个具体的C++实现示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Accept: 17Submit: 61
Time Limit: 1000 mSecMemory Limit : 32768 KB

Problem Description

Given you one n-digital positive integer a,After removing any of them k( k < n) digits, the remaining figures form a new positive integer according to the origin order. For a given n-digital positive integers a and positive integer k. Now ask you to find a algorithm to minimize the remaining integer.

Input

The first line contains one integer t, represents the number of test cases.

Then following t lines,each line contain two numbers a,k (0 < a < 10^1000, k is less than the length of a).

Output

Output the mininum number after the deletion.(the number can not contain leading zero)">it means that we should ignore the leading zeros of the output number

Sample Input

1 178543 4

Sample Output

13
//题目的意思很简单(我英语这么差的人都看得懂,我想应该没人看不懂)
//题目也不难, 注意处理好"0"就OK了,
//但因为多写了一个"=",
//害我折腾了一天..>-.-<
//整得我又是重写, 又手debug查....
//晚上玩了会DNF, 再拿起程序来调试,
//突然...
//发现一组数据有误(终于看到错误的数据了,,,,心里那个激动啊)
//再debug了一遍...
//原来是"<"写成"<="了.....
orz orz orz....
//调试无数次的程序, 看起来有点乱....
#include<iostream> using namespace std; int main() { char c[1002],max; int n,k,i,len,t,zt,zi,tmp,j; bool flag,flag2; scanf("%d",&n); while(n--) { scanf("%s%d",c,&k); len=strlen(c); max=c[0]; zt=zi=0; tmp=k; flag2=flag=false; for(i=0;i<len;i++) { if(c[i]=='0') { if(tmp-i+zt>=0) for(j=zi;j<=i;j++) c[j]='A'; else { zi=i; flag2=true; break; } k=tmp-(i-zt); max=c[i+1]; zt++; zi=i; } else if(max>c[i]) { k--; t=i-1; while(c[t]=='A') t--; c[t]='A'; while(c[t]=='A') t--; if(t<0) max=c[i]; else max=c[t]; i--; } else if(max<c[i]) max=c[i]; if(k==0) break; } if(k!=0) { if(flag2) i=zi-1; else i=len-1; for(;i>=0;i--) { if(c[i]!='A') {c[i]='A';k--;} if(k==0) break; } } for(i=0;i<len;i++) { if(flag) { if(c[i]!='A') printf("%c",c[i]); } else { if(c[i]!='A'&&c[i]!='0') {printf("%c",c[i]);flag=true;} } } if(!flag) printf("0"); printf("/n"); } return 0; }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值