Official

A - UFO襲来 / UFO Invasion Editorial by tatyam


プログラミングの学習を始めたばかりで何から手をつけるべきかわからない方は、まずは「practice contest」 の問題A「Welcome to AtCoder」をお試しください。言語ごとに解答例が掲載されています。


この問題では、\(S\) を文字列として入力し、\(S\)\(1\) 文字目から \(4\) 文字目、 \(2\) 文字目から \(5\) 文字目、… が ZONe であるかを調べれば良いです。
また、各言語の機能を使うことで、より簡単に解けることがあります。

回答例 (C++)

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

int main(){
    string S;
    cin >> S;
    int ans = 0;
    if(S.substr(0, 4) == "ZONe") ans++;
    if(S.substr(1, 4) == "ZONe") ans++;
    if(S.substr(2, 4) == "ZONe") ans++;
    if(S.substr(3, 4) == "ZONe") ans++;
    if(S.substr(4, 4) == "ZONe") ans++;
    if(S.substr(5, 4) == "ZONe") ans++;
    if(S.substr(6, 4) == "ZONe") ans++;
    if(S.substr(7, 4) == "ZONe") ans++;
    if(S.substr(8, 4) == "ZONe") ans++;
    cout << ans << endl;
}

回答例 (Python)

print(input().count("ZONe"))

posted:
last update: