Submission

Status:

[PPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: 1234

Problemset: ตรวจบัตรเครดิต

Language: cpp

Time: 0.002 second

Submitted On: 2025-06-01 19:26:01

#include <iostream>
#include <string>
using namespace std;

int main() {
    string s;
    cin >> s; 

    int lastDigit = s[15] - '0';

    string core = s.substr(0, 15);

    for (int i = 0, j = (int)core.size() - 1; i < j; i++, j--) {
        swap(core[i], core[j]);
    }

    int sum = 0;
    for (int i = 0; i < 15; i++) {
        int d = core[i] - '0';
        if (i % 2 == 0) {
            d = d * 2;
        }

        if (d >= 10) {
            sum += (d / 10) + (d % 10);
        } else {
            sum += d;
        }
    }

    int digit_check = (10 - (sum % 10)) % 10;

    if (digit_check == lastDigit) {
        cout << "yes";
    } else {
        cout << "no";
    }

    return 0;
}