SDUT 2072 删数问题

删数问题
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   

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值