Submission

Status:

[PPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: peilin

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

Language: c

Time: 0.001 second

Submitted On: 2025-10-12 13:47:08

#include <stdio.h>
#include <string.h>

int main() {
    char cc[17];
    scanf("%16s", cc);

    int digits[16];
    for(int i = 0; i < 16; i++) {
        digits[i] = cc[i] - '0';
    }

    int last_digit = digits[15];
    int reversed[15];
    for(int i = 0; i < 15; i++) {
        reversed[i] = digits[14 - i];
    }

    for(int i = 0; i < 15; i++) {
        if(i % 2 == 0) {
            reversed[i] *= 2;
        }
    }

    int sum = 0;
    for(int i = 0; i < 15; i++) {
        if(reversed[i] > 9) {
            sum += reversed[i] / 10;
            sum += reversed[i] % 10;
        } else {
            sum += reversed[i];
        }
    }

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

    if(check_digit == last_digit) {
        printf("yes\n");
    } else {
        printf("no\n");
    }

    return 0;
}