B - Cyclic Editorial by en_translator
For beginners
- If you are new to learning programming and do not know where to start, please try Problem A "Welcome to AtCoder" from practice contest. There you can find a sample code for each language.
- Also, if you are not familiar with problems in programming contests, we recommend you to try some problems in "AtCoder Beginners Selection".
- 「C++入門 AtCoder Programming Guide for beginners (APG4b)」 is a C++ tutorial for competitive programmers. Sadly, this is only in Japanese too.
- 「Python入門 AtCoder Programming Guide for beginners (APG4bPython)」 is a Python tutorial for competitive programmers. Again, this is only in Japanese.
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}")
posted:
last update: