您的位置:首页 > 其它

SDUT 2072 删数问题

2017-04-08 15:46 267 查看
删数问题

Time Limit: 1000MS Memory Limit: 65536KB

Submit Statistic Discuss

Problem Description

键盘输入一个高精度的正整数n(≤100位),去掉其中任意s个数字后剩下的数字按照原来的左右次序组成一个新的正整数。编程对给定的n与s,寻找一种方案,使得剩下的数字组成的新数最小。

Input

输入有多组 每组包括原始数n,要去掉的数字数s;

Output

输出去掉s个数后最小的数

Example Input

178543 4

Example Output

13

这道题wa了很多次,其中有没处理前导0,输出的数据是000,输入数据是000等问题,还有手误a[i]<=a[i+1]写成a[i]<a[i+1]导致像80023 3这样的数据错误。

#include <bits/stdc++.h>
using namespace std;

int main()
{
char a[110];
int s,i;
while(cin>>a)
{
cin>>s;
int t = s;
int len2 = strlen(a);
if(len2<=s)
{
cout<<"0"<<endl;
continue;
}
while(s>0)
{
i = 0;
int len = strlen(a);
while(i < len && a[i]<=a[i+1])
i++;
while(i<len)
{
a[i] = a[i+1];
i++;
}
s--;
}
i=0;
//if(a[0]=='0')
//{
while(a[i]=='0')
i++;
// }
if(i==len2-t)
cout<<"0";
for(int j = i;j < len2-t;j++)
printf("%c",a[j]);
cout<<endl;
}
return 0;
}
//101 1      80023 3
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: