Millet oj
Remove k-bit minimum
description
A line number of a numeric string of N digits, represented by the string is a positive integer. Remove the string of K digits, the remaining numbers are all possible in the least.
Assumptions:
Length of the string must be greater than equal to K
string does not begin with 0
Input
numeric string (0 <N <20) a row of N digits, and a positive integer K (K <N), the two data separated by spaces, such as: 14,322,193.
Export
Smallest possible number string after removal of K bits. 1,432,219 removed as 4, 3, 2 3 digits obtained after 1219, the minimum value of all possible.
This problem is relatively simple. . . . . . . . . . First read out then. . . . . From the uppermost bit and do a bit for each judge, look at this potential energy can not be deleted, if you can just delete and update the remaining number of bits that can be deleted (using a program to represent the parameter)
And finally the output of the previous character 0 gave deleted just fine. . . . . . . . . . . . . . . . . . . . . . . . This place has a pit. . . All numbers are also remaining 0 0 can not all be deleted and, finally, the output of 0 .. . . . .
For example this combination 12345678900. . .
#pragma warning(disable:4996)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include <ctype.h>
int main()
{
char str1[20],spark[20];
static int a,len,leave,i,j,k,flag,gggg;//零时中转
char line[1000];
scanf("%s %d",str1,&a);//a为
//printf("%s\n", str1);
len = strlen(str1);
for (i = 0; i <=len; i++)
{
flag = 0;
for (j = 1; j < a+1; j++)//a位前位向后看
{
if (str1[i] > str1[i + j])
flag = 1;
}
if (flag == 1)
{
str1[i] = '0';
a--;
}
//printf("%d\n", a);
else
spark[k++] = str1[i];
}
len = strlen(spark);
int count = 0;
for (i = 0; i < len; i++)
{
if (spark[i] == '0')
count++;
}
if (count == len)
{
printf("0");
return 0;
}
for (i = 0; i < len; i++)
{
if (spark[i] == '0')
// gggg = 1;
;
else gggg = 2;
if (gggg == 2)
printf("%c",spark[i]);
}
//printf("%d\n", a);
//printf("%s\n", str1);
system("pause");
return 0;
}
Here #pragma warning (disable: 4996) can be masked using the rules of scanf_s vs. . . . . . . Then system ( "pause") allows to see the results after the implementation of the program. . Convenient debugging. . . . . . . . .
. . . .
.
.
.
.
.
.
.
.
over.
.
.