公式

A - Penalty Kick 解説 by en_translator


For beginners

In this problem, you are asked to implement input, output, loop operation using the for statement, arithmetic operations, and handling strings.

This problem can be solved by, for example, first preparing an empty string, scan the \(1\)-th through \(N\)-th kick, and appending o if it succeeds or x if it fails. For the details of implementation, please refer to the sample code below.

Sample code (C++):

#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  string S = "";
  for (int i = 1; i <= N; ++i) {
    if (i % 3 == 0) S += 'x';
    else S += 'o';
  }
  cout << S << endl;
}

Sample code (Python):

N = int(input())
S = ""

for i in range(1,N+1):
    if i%3 == 0:
        S += "x"
    else:
        S += "o"

print(S)

投稿日時:
最終更新: