Official
A - Rotate Editorial by physics0523
以下のような方針でACすることもできます。
- \(abc\) の桁和である \(a+b+c\) を求め、これを \(111\) 倍した値を出力する。
この解法が正当である理由は以下のように説明されます。
\(abc=100a+10b+c\) とする。
\(abc+bca+cab\)
\(=(100a+10b+c)+(100b+10c+a)+(100c+10a+b)\)
\(=111(a+b+c)\)
実装例(C++):
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin >> s;
int tg=0;
tg+=(s[0]-'0');
tg+=(s[1]-'0');
tg+=(s[2]-'0');
cout << 111*tg << '\n';
return 0;
}
posted:
last update: