Submission
Status:
[PPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: Hxluk.ka
Problemset: ตรวจบัตรเครดิต
Language: c
Time: 0.002 second
Submitted On: 2025-10-11 09:40:43
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node *next;
};
struct Node* createNode(int val) {
struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
if (newNode == NULL) {printf("Allocated fail"); return NULL;}
newNode->data = val;
newNode->next = NULL;
return newNode;
}
struct Node* pushNode(struct Node *node, int val) {
if (node == NULL) {printf("Can't push to null node\n"); return NULL;}
struct Node* new = createNode(val);
node->next = new;
return new;
}
int main() {
char creds[17];
scanf("%s", creds);
struct Node *head = createNode(0);
struct Node *tail = head;
for (int i = 0; i < 15; i++) {
int digit = creds[i] - '0';
if (i%2==0)digit *= 2;
if (digit > 9) {
tail = pushNode(tail, digit/10);
tail = pushNode(tail, digit%10);
continue;
}
else tail = pushNode(tail, digit);
}
head = head->next;
int sum = 0;
for (int i = 0; head!=NULL; i++) {
int val = head->data;
tail = head;
head = head->next;
free(tail);
sum+=val;
}
if ((10 - (sum%10))%10 == creds[15]-'0') printf("yes");
else printf("no");
return 0;
}