# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
147254 | ipaljak | Lun (COCI19_lun) | C++14 | 3 ms | 376 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) cerr << #x << " " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
typedef long long llint;
const int MOD = 1e9 + 7;
const int MAXN = 105;
int n;
char s[MAXN];
bool check(int x) {
int sum = 0;
for (int i = 1; i < n; ++i) {
int d = (s[n - i - 1] - '0');
if (s[n - i - 1] == 'x') d = x;
if (i % 2 == 1) d *= 2;
if (d >= 10) d = 1 + (d % 10);
sum += d;
}
sum *= 9; sum %= 10;
int val = s[n - 1] - '0';
if (s[n - 1] == 'x') val = x;
return sum == val;
}
int main(void) {
scanf("%d", &n);
scanf("%s", s);
for (int x = 0; x < 10; ++x) {
if (s[0] == 'x' && x == 0) continue;
if (check(x)) {
printf("%d\n", x);
break;
}
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |