A - Rotate 解説 by en_translator
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 to problems in programming contests, we recommend you to try some problems in “AtCoder Beginners Selection” (https://atcoder.jp/contests/abs).
「競プロ典型 90 問」(Typical 90 Problems of Competitive Programming) (https://atcoder.jp/contests/typical90) is a collection of typical 90 competitive programming problems; unfortunately, currently the problem statements are all Japanese.
「C++入門 AtCoder Programming Guide for beginners (APG4b)」(https://atcoder.jp/contests/APG4b) is a C++ tutorial for competitive programmers. Sadly, this is only in Japanese too.
The problem can be solved by processing as follows
- Receive \(a\), \(b\) and \(c\) as characters
- Concatenate these characters in the ordered specified in the problem statement to obtain strings
- Convert the strings to integers and find their sum
Sample code (C++)
#include<bits/stdc++.h>
using namespace std;
int main(){
char a, b, c;
cin >> a >> b >> c;
string abc = string({a, b, c});
string bca = string({b, c, a});
string cab = string({c, a, b});
int ans = stoi(abc) + stoi(bca) + stoi(cab);
cout << ans << endl;
}
Sample code (Python)
a, b, c = input()
abc = a + b + c
bca = b + c + a
cab = c + a + b
ans = int(abc) + int(bca) + int(cab)
print(ans)
Alternatively, you may receive the input as an integer \(N\), in which case you may obtain each digit by the operation like \(N\%10\) and \(N/10\%10\) (where \(\%\) denotes the modulo operation)
投稿日時:
最終更新: