• TZOJ 4493: Remove Digits


    4493: Remove Digits 分享至QQ空间

    时间限制(普通/Java):1000MS/3000MS     内存限制:65536KByte
    总提交: 329            测试通过:77

    描述

    Given an N-digit number, you should remove K digits and make the new integer as large as possible.

    输入

    The first line has two integers N and K (1 ≤ K<N≤500000).
    The next line has a N-digit number with no leading zero.

    输出

    Output the largest possible integers by removing K digits.

    样例输入

    样例输出

     

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 char s[500005];
     4 int main()
     5 {
     6     ios::sync_with_stdio(false);
     7     int n,k,num=0;
     8     char c;
     9     s[0]='9';
    10     cin>>n>>k;
    11     for(int i=0;i<n;i++){
    12         cin>>c;
    13        while(c>s[num]){
    14             if(!k||!num) break;
    15             num--,k--;
    16        }
    17         s[++num]=c;
    18    }
    19     if(k)
    20         num=num-k;
    21     s[++num]='';
    22     cout << s+1 << endl;
    23     return 0;
    24 }
    View Code
  • 相关阅读:
    PHP PDO
    常用JavaScript字符串方法简述
    命名
    jquery远程班备忘
    html历史
    CSS3的翻转效果
    正则
    排序算法
    firebug的调试,console
    跨域
  • 原文地址:https://www.cnblogs.com/qq-1585047819/p/10679018.html
Copyright © 2020-2023  润新知