P1055 0分求助

P1055 [NOIP2008 普及组] ISBN 号码

BaiduPhoto @ 2024-07-06 18:38:05

#include <iostream>
#include <string>
using namespace std;
int identification[15], code[13], ans=0;
int main()
{
    for (int i = 1; i <=13; i++)
    {
        cin >> identification[i];
        if(i!=2 || i!=6 || i!=12)
        for (int j = 1; j <= 10; j++)
        {
            code[j]=identification[i];
            ans+code[j]*(j-1);
        }
    }
    ans=ans%11;
    if (ans==10) ans=X;
    if (ans==identification[13])cout << "Right" << endl;
    else identification[13]=ans;
    for (int i = 1; i <=13; i++)
    {
        cout << identification[i];
    }
    return 0;
}

by Magallan_forever @ 2024-07-06 18:54:17

else那里应该打大括号,不然又right又会输出别的,以及这个过不了样例吧


by Magallan_forever @ 2024-07-06 18:56:33

X又是哪里来的


by Magallan_forever @ 2024-07-06 18:57:32

'X'


by BaiduPhoto @ 2024-07-06 19:10:07

@Magallan_forever 十分感谢大佬指导!!!


by BaiduPhoto @ 2024-07-06 19:12:57

@Magallan_forever 但还是null


by BaiduPhoto @ 2024-07-06 19:16:15

@Magallan_forever 现在是30


by Magallan_forever @ 2024-07-06 19:27:22

ans+code[j]*(j-1);这里并没有修改到值,只是一个表达式而已

建议仔细检查一下自己的代码,每一步的实际效果是否符合自己的期望


by BaiduPhoto @ 2024-07-06 19:31:33

@Magallan_forever 谢谢


|