작성일 :

문제 링크

31607번 - 和の判定 (Sum Checker)

설명

세 정수 A, B, C 중 하나가 나머지 두 수의 합인지 확인하는 문제입니다.


접근법

A+B=C, A+C=B, B+C=A 중 하나라도 성립하면 1을, 아니면 0을 출력하면 됩니다.


Code

C#

1
2
3
4
5
6
7
8
9
10
11
12
using System;

class Program {
  static void Main() {
    var a = int.Parse(Console.ReadLine()!);
    var b = int.Parse(Console.ReadLine()!);
    var c = int.Parse(Console.ReadLine()!);

    var ok = (a + b == c) || (a + c == b) || (b + c == a);
    Console.WriteLine(ok ? 1 : 0);
  }
}

C++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int a, b, c; cin >> a >> b >> c;
  
  bool ok = (a + b == c) || (a + c == b) || (b + c == a);
  cout << (ok ? 1 : 0) << "\n";

  return 0;
}