Submission
Status:
[PPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: pond4545
Problemset: ตรวจบัตรเครดิต
Language: cpp
Time: 0.003 second
Submitted On: 2025-10-08 11:08:00
#include <iostream>
#include <string>
using namespace std;
int main()
{
string credit;
cin >> credit;
int sum = 0;
int len = credit.length();
int check = credit[len - 1] - '0'; // last digit is the check digit
// process digits from right to left (excluding check digit)
for (int i = len - 2, pos = 1; i >= 0; i--, pos++) {
int n = credit[i] - '0'; // convert char to int
if (pos % 2 == 1) { // every second digit from right
n *= 2;
if (n > 9) n = n / 10 + n % 10;
}
sum += n;
}
int verify = (10 - (sum % 10)) % 10;
if (verify == check)
cout << "yes";
else
cout << "no";
return 0;
}