たなしょのメモ

日々勉強していることをつらつらと

B - Papers, Please

はじめに

たなしょです。

最近FGOにはまっています。 楽しいですね。

問題文

atcoder.jp

考え方

まず偶数の数をカウントして、次に3か5で割り切れる数をカウントをする。

for (int i = 0; i<a; i++) {
        if (data[i] % 2 == 0) {
            ++cnt1;
            if ((data[i] % 3 == 0) || (data[i] % 5 == 0)) {
                ++cnt2;
            }
        }
    }

もし偶数の数と3か5で割り切れる数のカウントが一致していた場合、"APPROVED"

一致していなければ"DENIED"を出力する。

if (cnt1 == cnt2) {
        cout << "APPROVED" << endl;
    } else {
        cout << "DENIED" << endl;
    }

いざ実装

#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <map>
typedef long long ll;

using namespace std;

int main(void)
{
    int a;
    cin >> a;

    vector<int> data(a);

    int cnt1 = 0;
    int cnt2 = 0;

    for (int i = 0; i<a; i++) {
        cin >> data[i];
    }

    for (int i = 0; i<a; i++) {
        if (data[i] % 2 == 0) {
            ++cnt1;
            if ((data[i] % 3 == 0) || (data[i] % 5 == 0)) {
                ++cnt2;
            }
        }
    }

    if (cnt1 == cnt2) {
        cout << "APPROVED" << endl;
    } else {
        cout << "DENIED" << endl;
    }

    return 0;
}

最後に

ガチャをひいたら刑部姫が出ました。

かわいいですね。

最後まで読んでいただいてありがとうございました。 もしよろしければtwitterアカウント(@piklus100yen)もフォローしていただけると幸いです!