不定期やるだけ(AOJ)

やるだけ.

Flick Input(AOJ 2417)

時代を感じる.

#include <iostream>

std::string table = "  kstnhmyr", table2 = "aiueo", table3 = "TLURD";

int main(){
    std::string S, T = "";
    std::cin >> S;
    for(int i=0;i<S.size();i+=2){
        if(S[i] == '0'){
            if(S[i+1] == 'T'){T += "wa";}
            else if(S[i+1] == 'D'){T += "wo";}
            else{T += "nn";}
        }else if(S[i] == '1'){
            T += table2[table3.find(S[i+1])];
        }else{
            T += table[S[i]-'0'];
            T += table2[table3.find(S[i+1])];
        }
    }

    std::cout << T << std::endl;
}

Kagisys(AOJ 2440)

unordered_mapで殴る.

#include <iostream>
#include <unordered_map>

std::unordered_map<std::string, int> m;

int main(){
    int N;
    std::cin >> N;

    for(int i=0;i<N;i++){
        std::string key;
        std::cin >> key;

        ++m[key];
    }

    int M;
    std::cin >> M;

    bool locked = true;
    for(int i=0;i<M;i++){
        std::string id;
        std::cin >> id;

        if(m[id] > 0){
            if(locked){
                std::cout << "Opened by " << id << std::endl;
            }else{
                std::cout << "Closed by " << id << std::endl;
            }
            locked ^= 1;
        }else{
            std::cout << "Unknown " << id << std::endl;
        }
    }
}

Parentheses(AOJ 2490)

同じ問題3回ぐらいみた.

#include <iostream>

int N;

bool solve(){
    int opened = 0;
    for(int i=0;i<N;i++){
        char c;
        int n;
        std::cin >> c >> n;

        if(c == '('){
            opened += n;
        }else{
            if(n > opened){return false;}
            opened -= n;
        }
    }

    return opened == 0;
}

int main(){
    std::cin >> N;

    std::cout << (solve() ? "YES" : "NO") << std::endl;
}

Summer of KMC(AOJ 2216)

コミケ行ってみたい.

#include <cstdio>

int main(){
    int A, B;
    while(scanf("%d %d", &A, &B), A || B){
        B -= A;
        printf("%d %d %d\n", B % 500 / 100, B % 1000 / 500, B / 1000);
    }
}

koukyoukoukokukikou(AOJ 2252)

the やるだけって感じ.

#include <iostream>

int main(){
    std::string right = "yuiophjklnm";
    std::string S;
    while(std::cin >> S, S != "#"){
        int prev = -1, res = 0;
        for(const auto &c : S){
            int which = right.find(c) != std::string::npos;
            if(prev == -1){
                prev = which;
            }else if(which != prev){
                ++res; prev = which;
            }
        }

        printf("%d\n", res);
    }
}

KUPC(AOJ 2271)

JOI Emblem.

#include <iostream>
#include <algorithm>

int count[26];

int main(){
    std::string S;
    std::cin >> S;

    for(const auto& c : S){
        if(std::islower(c)){continue;}
        ++count[c&63];
    }

    printf("%d\n", std::min({count['K'&63], count['U'&63], count['P'&63], count['C'&63]}));
}

Palindromic Number(AOJ 2489)

疲れてきた.

#include <iostream>

bool isPalindromic[10002];
int A[10002], B[10002];

int main(){
    for(int i=0;i<=10001;i++){
        std::string s = std::to_string(i);
        bool f = true;
        for(int j=0;j<s.size();j++){
            if(s[j] != s[s.size()-1-j]){f = false; break;}
        }
        if(f){isPalindromic[i] = true;}
    }
    
    int prev;
    for(int i=0;i<=10001;i++){
        if(isPalindromic[i]){prev = i;}
        A[i] = prev;
    }

    for(int i=10001;i>=0;i--){
        if(isPalindromic[i]){prev = i;}
        B[i] = prev;
    }
    
    int N;
    std::cin >> N;

    if(std::abs(N-A[N]) <= std::abs(N-B[N])){
        std::cout << A[N]<< std::endl;
    }else{
        std::cout << B[N]<< std::endl;
    }
    
}

Programming Contest(AOJ 2259)

YukiCoderは偉大.(49byte)

gets;p$<.map{|s|s.split.map(&:to_i).inject:+}.max