Submission
Status:
[PPPPPPPPPP]
Score: 100
User: Namkhing
Problemset: ตรวจบัตรเครดิต
Language: cpp
Time: 0.002 second
Submitted On: 2025-04-10 23:45:14
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(nullptr)->ios_base::sync_with_stdio(false);
string s;
cin >> s;
int x = s.back() - '0';
s.pop_back();
reverse(s.begin(), s.end());
int ans = 0;
for (int i = 0; i < s.size(); i++) {
if (i % 2 == 0) {
int val = s[i] - '0';
val *= 2;
if (val >= 10) ans += val - 9;
else ans += val;
}
else {
ans += s[i] - '0';
}
}
int r = (10 - ans % 10) % 10;
if (r == x) cout << "yes";
else cout << "no";
}