2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Atcoder始めました

今日からAtcoderの学習記録を残そうと思います!
今回取り組んだ問題は過去問ABC042のA問題です。
自分が書いたコード(100点でも100点ではなくても)から正解を参照し、学んでいければと思います!

最初に自分が書いたコードはこちらです。

#include <iostream>
using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    if ((a == 5 && b == 5 && c == 7) ||
        (a == 5 && b == 7 && c == 5) ||
        (a == 7 && b == 5 && c == 5)) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}

以下がけんちょんの競プロ精進記録に掲載されていた解答です

#include <bits/stdc++.h>
using namespace std;

int main() {
    // ソートしたいので配列で受け取る
    vector<int> v(3);
    cin >> v[0] >> v[1] >> v[2];
    
    // ソートする
    sort(v.begin(), v.end());
    
    // 5, 5, 7 になっているかどうか
    if (v[0] == 5 && v[1] == 5 && v[2] == 7) cout << "YES" << endl;
    else cout << "NO" << endl;
}

読みやすいかつコメントがしっかり残されていて分かりやすい...
解答では
5,7,5を作れるかどうかを判断するために、配列を作りソートして5,5,7が作成できれば判断できると考えコードが組まれていました。
詳しい説明は、是非サイトを参照してください!

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?