QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#723865#7698. ISBN ConversionMattTheNub#WA 1ms3752kbC++232.7kb2024-11-08 01:44:562024-11-08 01:44:57

Judging History

你现在查看的是最新测评结果

  • [2024-11-08 01:44:57]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3752kb
  • [2024-11-08 01:44:56]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

template <class T> using v = vector<T>;
using ll = long long;
using dd = long double;
using int2 = pair<int, int>;
using ll2 = pair<ll, ll>;
using dd2 = pair<dd, dd>;

#define f first
#define s second
#define all(x) begin(x), end(x)
istream &__cin = cin;
#ifdef DEV_MODE
#include "debug.h"
__cinwrapper __cin_wrapper;
#define cin __cin_wrapper
#else
#define dbg(...)
#define dbg2d(...)
#endif

template <class T1, class T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
  in >> p.first >> p.second;
  return in;
}
template <class T> istream &operator>>(istream &in, v<T> &v) {
  for (auto &x : v)
    in >> x;
  return in;
}
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

/*
 _______________________________________
( If you don't fail at least 90% of the )
( time, you're not aiming high enough.  )
(                                       )
( - Alan Kay                            )
 ---------------------------------------
        o   ^__^
         o  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||
*/

const bool INTERACTIVE = false;
const bool MULTITEST = true;
/******************************************************************************/

#pragma region templates

#pragma endregion templates

void solve() {
  string s;
  cin >> s;

  if (s[0] == '-' || s.back() == '-' || count(all(s), '-') > 3 ||
      (s.find('X') != string::npos && s.find('X') != s.size() - 1)) {
    cout << "invalid\n";
    return;
  }
  for (int i = 0; i < s.size() - 1; i++) {
    if (s[i] == '-' && s[i + 1] == '-') {
      cout << "invalid\n";
      return;
    }
  }
  if (count(all(s), '-') == 3) {
    if (s[s.size() - 2] != '-') {
      cout << "invalid\n";
      return;
    }
  }
  int sum = 0;
  int c = 10;
  for (auto x : s) {
    if (x == '-')
      continue;
    if (x == 'X') {
      x = 10;
    } else {
      x -= '0';
    }
    sum += c * x;
    c--;
    sum %= 11;
  }
  if (sum != 0) {
    cout << "invalid\n";
    return;
  }
  s.pop_back();
  s = "978-" + s;

  c = 1;
  for (auto x : s) {
    if (x == '-')
      continue;
    x -= '0';
    sum += c * x;
    c = 4 - c;
    sum %= 10;
  }
  s.push_back('0' + ((10 - sum) % 10));
  cout << s << '\n';
}

int main() {
#ifdef DEV_MODE
  debug_start(INTERACTIVE, "i.txt");
#else
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  int t;
  if (MULTITEST)
    cin >> t;
  else
    t = 1;
  while (t--)
    solve();

#ifdef DEV_MODE
  debug_exit(INTERACTIVE);
#endif
}
#ifdef DEV_MODE
#include "debug.cpp"
#endif

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3752kb

input:

4
3-540-4258-02
039428013X
3-540-42580-2
0-14-028333-3

output:

invalid
978-0394280134
978-3-540-42580-9
invalid

result:

ok 4 lines

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3664kb

input:

25
----------
-----------
------------
-------------
XXXXXXXXXX
XXXXXXXXXXX
XXXXXXXXXXXX
XXXXXXXXXXXXX
---------X
----------X
-----------X
01234567890
012345678901
0123456789012
-0123456789-
0123456789-
-0123456789
01--23456789
012345678--9
0123456789--
--0123456789
98765432-1
987-654-321
87-645-32-...

output:

invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
978-01234567897
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
978-98765432-0
978-987-654-320
978-87-645-32-5
invalid

result:

wrong answer 12th lines differ - expected: 'invalid', found: '978-01234567897'