删数问题(使用C语言)
Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description
键盘输入一个高精度的正整数n(≤100位),去掉其中任意s个数字后剩下的数字按照原来的左右次序组成一个新的正整数。编程对给定的n与s,寻找一种方案,使得剩下的数字组成的新数最小。
Input
输入有多组 每组包括原始数n,要去掉的数字数s;
Output
输出去掉s个数后最小的数
Sample Input
178543 4
Sample Output
13
Hint
Source
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int s;
int i,j,chang,t;
char n[150];
while(~scanf("%s %d",&n,&s))
{
chang=strlen(n);
t=s;
while(s--)
{
i=0;
while(i<chang&&n[i]<=n[i+1])
i++;
while(i<chang)
{
n[i]=n[i+1];
i++;
}
}
i=0;
if(n[0]=='0')
{
while(n[i]=='0') i++;
}
if(i==chang-t) printf("0");
else
for(j=i;j<chang-t;j++)
printf("%c",n[j]);
printf("\n");
}
return 0;
}