よじろめ覚書

私の理解度重視のソースコードです。

ABC150B - Count ABC

問題:B - Count ABC

#include <iostream>
#include <string>
using namespace std;

int main(void) {
    int n, pos = 0, ans = 0;
    string s;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    cin >> s;
    while (s.find("ABC", pos) != string::npos) {
        ans++;
        pos = s.find("ABC", pos) + 3;
    }

    cout << ans << "\n";
    return 0;
}

pos の位置をfind内に書いており、1WA。。

ABC149B - Greedy Takahashi

問題:B - Greedy Takahashi

#include <iostream>
using namespace std;

int main(void) {
    long long a, b, k;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a >> b >> k;
    a -= k;
    if (a < 0) {
        b += a;
        if (b < 0) {
            b = 0;
        }
        a = 0;
    }

    cout << a << " " << b << "\n";
    return 0;
}

ABC148B - Strings with the Same Length

問題:B - Strings with the Same Length

#include <iostream>
#include <string>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)

int main(void) {
    int n;
    string s, t;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    cin >> s >> t;
    REP(i, n) {
        cout << s[i] << t[i];
    }

    cout << "\n";
    return 0;
}