uva11491 Erasing and Winning

2021-07-08 01:07

阅读:639

标签:i++   getch   str   处理   turn   cst   lib   space   cstring   

边读入边处理 优化了速度
一开始有想错了的地方。处理输入有点想用stringstream, 的问题在于他把字符串连续的数字作为一个整体,遇到空格才分开,所以不适用

#include
#include
#include
#include
#includeusing namespace std;

const int maxn = 100005;
int s[maxn];
 
int main()
{
    int n, d;
    while (scanf("%d%d%*c", &n, &d) && n) {
        int t = 0;
        int a;
        d = n - d;
        for (int i = 0; i //位数相同,贪心策略为最高位最大
            a = getchar() - 0;
            while (t && t + n - i > d && a > s[t - 1]) {
                t--;
            }
            if (t  d) {
                s[t++] = a;
            }
        }
        for (int i = 0; i ) {
            printf("%d", s[i]);
        }
        printf("\n");
    }
 
    return 0;
}

 

uva11491 Erasing and Winning

标签:i++   getch   str   处理   turn   cst   lib   space   cstring   

原文地址:https://www.cnblogs.com/lqerio/p/9745604.html


评论


亲,登录后才可以留言!