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

个人做题记录

今天最近不少心烦事,唉

A. Suffix Three

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int t;
char s[1010];

int main() {
    scanf("%d", &t);
    while(t --) {
        scanf("%s", s + 1);
        int n = strlen(s + 1);
        if(s[n] == 'o') cout << "FILIPINO
";
        else if(s[n] == 'a') cout << "KOREAN
";
        else cout << "JAPANESE
";
    }
    
    return 0;
}

B. Azamon Web Services

对字典序理解不够,导致做的时候WA了很多次。注意贪心

#include <bits/stdc++.h>
using namespace std;
const int N = 5050;
int t;
string s, c;

inline void change() {
    string tmp = s;
    sort(tmp.begin(), tmp.end());
    
    int n = s.length();
    for(int i = 0; i < n; i++) {
        if(s[i] != tmp[i]) {
            for(int j = n - 1;j > i; j--) {
                if(s[j] == tmp[i]) {
                    swap(s[i], s[j]);
                    return;
                }
            }
        }
    }
}

int main() {
    scanf("%d", &t);
    while(t --) {
        cin >> s >> c;
        change();
        if(s < c) cout << s << '
';
        else cout << "---" << '
';
    }
    
    return 0;
}
原文地址:https://www.cnblogs.com/FrankOu/p/14521419.html