公式

B - Cyclic 解説 by en_translator


For beginners

The implementation for this problem differs depending on how you receive \(N\). We introduce several ways.

Approach 1

Receive the input one character by one

Receive one character by one, letting them \(a,b\), and \(c\). Then all you need to do is print \(a,b\), and \(c\) as specified in the problem statement.

Sample code (C++)

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

int main() {
    char a, b, c;
    cin >> a >> b >> c;
    cout << b << c << a << " " << c << a << b << endl;
}

Sample code (Python3)

a, b, c = input()
print(f"{b}{c}{a} {c}{a}{b}")

Approach \(2\)

Receive the integer \(N\) into an integer type

Find the hundreds, tens, and ones places of the integer \(N\), and print them as instructed in the problem statement. In our problem the hundreds digit is \(\lfloor \frac{N}{100} \rfloor\), the tens digit is the remainder when \(\lfloor \frac{N}{10} \rfloor\) is divided by \(10\), and the ones digit is the remainder of \(N\) by \(10\).

Sample code (C++)

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

int main() {
    int n;
    cin >> n;
    int a = n / 100, b = (n / 10) % 10, c = n % 10;
    cout << b << c << a << " " << c << a << b << endl;
}

Sample code (Python3)

n = int(input())
a = n // 100
b = (n // 10) % 10
c = n % 10
print(f"{b}{c}{a} {c}{a}{b}")

投稿日時:
最終更新: