键盘输入一个高精度的正整数 N(不超过 250 位),去掉其中任意 k 个数字后剩下的数字按原左右次序将组成一个新的非负整数。编程对给定的 N 和 k,寻找一种方案使得剩下的数字组成的新数最小。
输入两行正整数。
第一行输入一个高精度的正整数 n。
第二行输入一个正整数 k,表示需要删除的数字个数。
输出一个整数,最后剩下的最小数。
175438
4
13
#include<iostream>
using namespace std;
int n;
struct node
{
char data;
node* next;
};
node* creat()
{
char a;
a = getchar();
node* head = NULL, * tail = NULL;
while (a != '\n')
{
node* p = (node*)malloc(sizeof(node));
p->data = a;
p->next = NULL;
if (head == NULL)
{
head = p;
tail = p;
}
else
{
tail->next = p;
tail = p;
}
a = getchar();
}
return head;
}
int main()
{
node* head = (node*)malloc(sizeof(node));
head->next = creat();
cin >> n;
for (; n > 0; n--)
for (node* i = head; i->next->next != NULL; i = i->next)
{
if (i->next->data > i->next->next->data)
{
i->next = i->next->next;
break;
}
if (i->next->next->next == NULL)
{
i->next->next = NULL;
break;
}
}
node* i = head->next;
while (i != NULL && i->data == '0')
i = i->next;
if (i == NULL)
cout << 0;
else
{
while (i)
{
cout << i->data;
i = i->next;
}
}
return 0;
}
样例是 10 1 ide上输出都是0 但是oj过不了