Official
B - 前後 / Before After Editorial
by
B - 前後 / Before After Editorial
by
kyopro_friends
\(A+C=B\) と \(B+C=A\) のどちらが成立するかを if 文で判別し、指定された形式で出力します。
出力する際には、「値が正ならば先頭に + をつける」というフォーマットを適切に指定することで、+50 のように符号付きで出力することができます。
実装例(C++)
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c;
cin >> a >> b >> c;
if(a+c==b){
printf("%d -> %d (%+d)\n", a, b, c);
}else{
printf("%d -> %d (%+d)\n", b, a, c);
}
}
実装例(Python)
A,B,C=map(int,input().split())
if A+C==B:
print(f"{A} -> {B} ({C:+})")
else:
print(f"{B} -> {A} ({C:+})")
posted:
last update:
