Submission
Status:
[PPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: PEPSEALSEA
Problemset: บาร์โค้ด
Language: cpp
Time: 0.003 second
Submitted On: 2026-09-26 22:05:49
#include <iostream>
#include <string>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
string barcode;
if (!(cin >> barcode) || barcode.length() != 13) {
cout << "NO\n";
return 0;
}
int checkdigit = barcode[12] - '0';
int sum_even = 0;
int sum_odd = 0;
for (int pos = 2; pos <= 13; pos++) {
int digit = barcode[13 - pos] - '0';
if (pos % 2 == 0) {
sum_even += digit;
} else {
sum_odd += digit;
}
}
int total_sum = (sum_even * 3) + sum_odd + checkdigit;
if (total_sum % 10 == 0) {
cout << "YES\n";
} else {
cout << "NO\n";
}
return 0;
}