Loading

Codeforces Round #604 (Div. 2) A、B

此为个人向的练习记录

题目传送

A. Beautiful String

很简单的构造字符串问题,记得处理一下以?开头的情况

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 3;
int t;
char s[N], p[] = {'a','b','c'};

void ok(int x) {
    for(int w = 0; w < 3; w ++) {
        if(p[w] != s[x - 1] && p[w] != s[x + 1]) {
            s[x] = p[w]; return;
        }
    }
}

int main() {
    scanf("%d", &t);
    while(t --) {
        bool f = 0;
        scanf("%s", s);
        if(s[0] == '?') ok(0);
        for(int i = 1; s[i]; i++) {
            if(s[i] != '?') {
                if(s[i - 1] == s[i]) f = 1; 
            }else ok(i);
        }
        if(f) puts("-1");
        else puts(s);
    }
    
    return 0;
}

B. Beautiful Numbers

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 3;
int a[N];
int n, t, x;

int main() {
    scanf("%d", &t);
    while(t --) {
        scanf("%d", &n);
        for(int i = 1; i <= n; i++) {
            scanf("%d", &x); a[x] = i;
        }
        
        int l = 0x3f3f3f3f, r = -1;
        for(int i = 1; i <= n; i++) {
            l = min(l, a[i]);
            r = max(r, a[i]);
            if(r - l + 1 == i) cout << 1;
            else cout << 0;
        }
        cout << '\n';
    }
    
    return 0;
}
posted @ 2021-03-02 13:35  Frank_Ou  阅读(55)  评论(0编辑  收藏  举报