本地几毫秒,上去直接CE

P1055 [NOIP2008 普及组] ISBN 号码

mei_shaoting @ 2024-04-06 20:55:31

本地能跑,提交就CE了(悲

#include <bits/stdc++.h>
using namespace std;
string a;
int num[15];
char n;
int cnt;
int s;

int main(int argc, char const *argv[])
{
    cin >> a;
    for (int i = 0; i < 13; i++)
    {
        if (a[i] != '-')
        {
            num[cnt] = a[i] - '0';
            cnt++;
        }
        if (cnt == 9)
        {
            break;
        }
    }
    s = (num[0] * 1 + num[1] * 2 + num[2] * 3 + num[3] * 4 + num[4] * 5 + num[5] * 6 + num[6] * 7 + num[7] * 8 + num[8] * 9) % 11;
    if (s != 10)
    {
        n = '0' + s;
    }
    else
    {
        n = 'X';
    }
    if (n == a[a.size() - 1])
    {
        cout << "Right";
    }
    else
    {
        a[a.size() - 1] = n;
        cout << a;
    }

    return 0;
}

by dctc800d @ 2024-04-06 20:57:56

完了,我通过了。。。

选错语言了吧


by __O_w_O__ @ 2024-04-06 21:00:43

@mei_shaoting
你这交上去的代码是个什么玩意啊。。。

#include <bits/stdc++.h>
using namespace std;
string a;
int num[15];
char n;
int cnt;
int s;#include <bits/stdc++.h>
using namespace std;
string a;
int num[15];
char n;
int cnt;
int s;

int main(int argc, char const *argv[])
{
    cin >> a;
    for (int i = 0; i < 13; i++)
    {
        if (a[i] != '-')
        {
            num[cnt] = a[i] - '0';
            cnt++;
        }
        if (cnt == 9)
        {
            break;
        }
    }
    s = (num[0] * 1 + num[1] * 2 + num[2] * 3 + num[3] * 4 + num[4] * 5 + num[5] * 6 + num[6] * 7 + num[7] * 8 + num[8] * 9) % 11;
    if (s != 10)
    {
        n = '0' + s;
    }
    else
    {
        n = 'X';
    }
    if (n == a[a.size() - 1])
    {
        cout << "Right";
    }
    else
    {
        a[a.size() - 1] = n;
        cout << a;
    }

    return 0;
}

int main(int argc, char const *argv[])
{
    cin >> a;
    for (int i = 0; i < 13; i++)
    {
        if (a[i] != '-')
        {
            num[cnt] = a[i] - '0';
            cnt++;
        }
        if (cnt == 8)
        {
            break;
        }
    }
    s = (num[0] * 1 + num[1] * 2 + num[2] * 3 + num[3] * 4 + num[4] * 5 + num[5] * 6 + num[6] * 7 + num[7] * 8 + num[8] * 9) % 11;
    if (s != 10)
    {
        n = '0' + s;
    }
    else
    {
        n = 'X';
    }
    if (n == a[a.size() - 1])
    {
        cout << "Right";
    }
    else
    {
        a[a.size() - 1] = n;
        cout << a;
    }

    return 0;
}

代码提交的时候不小心粘贴了两次吧。。。


|