Submission #48663937


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
int main() {

    string s; 
    cin >> s;
    for (int i = 0; i < (1 << 3); i++) {
        //↑000から1000まで調べるよ(ただし < なので1000は入らず、1000-1の111まで)
        int n = s[0] - '0';
        //↑文字を整数に変換するテクニック 文字 - '0' です。
        vector<char>ans(3);
        //↑組み合わせ(+か-)を配列に保存しておく(出力するときに便利)
        //↓各(iの)組み合わせの時にそのbitが立っているか(それが+か-か)を調べるよ
        for (int j = 0; j < 3; j++) {
            if (i & (1 << j)) {
                //bitが立っている(+)
                n += s[j + 1] - '0';
                ans[j] = '+';
            }
            else {
                //bitが立っていない(-)
                n -= s[j + 1] - '0';
                ans[j] = '-';
            }
        }
        if (n == 7) {
            cout << s[0] << ans[0] << s[1] << ans[1] << s[2] << ans[2] << s[3] << "=7" << endl;
            return 0;
        }
    }

}

Submission Info

Submission Time
Task C - Train Ticket
User yoss
Language C++ 23 (gcc 12.2)
Score 300
Code Size 1089 Byte
Status AC
Exec Time 1 ms
Memory 3592 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 19
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
01.txt AC 1 ms 3424 KiB
02.txt AC 1 ms 3592 KiB
03.txt AC 1 ms 3412 KiB
04.txt AC 1 ms 3428 KiB
05.txt AC 1 ms 3444 KiB
06.txt AC 1 ms 3428 KiB
07.txt AC 1 ms 3412 KiB
08.txt AC 1 ms 3420 KiB
09.txt AC 1 ms 3416 KiB
10.txt AC 1 ms 3368 KiB
11.txt AC 1 ms 3416 KiB
12.txt AC 1 ms 3516 KiB
13.txt AC 1 ms 3440 KiB
14.txt AC 1 ms 3368 KiB
15.txt AC 1 ms 3424 KiB
16.txt AC 1 ms 3412 KiB
sample_01.txt AC 1 ms 3564 KiB
sample_02.txt AC 1 ms 3588 KiB
sample_03.txt AC 1 ms 3592 KiB