Submission
Status:
[PPPPPPPPPP]
Score: 100
User: solarsunny
Problemset: ตรวจบัตรเครดิต
Language: c
Time: 0.002 second
Submitted On: 2024-12-18 16:15:04
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
int c[16];
int main() {
char a[100];
scanf("%s", a);
for(int i=0; i<15; i++) {
c[i] = a[i]- '0';
}
int b = a[15]-'0';
for(int i=14; i>=0; i-=2) {
c[i] = c[i] * 2;
}
for(int i=0; i<15; i++) {
if(c[i] > 9) {
c[i] = c[i]%10 + 1;
}
}
int s=0;
for(int i=0; i<15; i++) {
s += c[i];
}
s = (10-(s%10))%10;
if(s == b) {
printf("yes");
} else {
printf("no");
}
printf("\n");
return 0;
}