imicola @ 2024-08-28 14:17:31
求大佬帮忙看看代码出错在哪,在本地运行正确,提交上后便WA和RE,下载测试点#1数据也无异常,输出正确但仍然判WA
#include<bits/stdc++.h>
using namespace std;
int main()
{
char ISBN[14]; //创建字符串
cin >> ISBN;
int check = ISBN[12] - '0'; //提取检查值
int arr[20],k;
for (int i = 0; i < 11; i++)
{
//跳过"-"
if (i == 1 || i == 5 )
{
continue;
}
else
{
arr[k] = ISBN[i] - '0'; //将九个字符记入到数组中
k++;
}
}
int becheck; //创建被检查值
for (int j = 1; j < 10; j++)
{
becheck += arr[j - 1]*j; //将九个数字按题目要求分别加进被检查值里
}
becheck %= 11; // 取mod11
if (becheck != 10 && becheck == check) //如果被检查值与检查值相等(被检查值 != 10)时
{
cout << "Right";
}
else if (becheck == 10)
{
if (check == 40) //"X"的ASCII - "0"的ASCII
{
cout << "Right";
}
else
{
char temp = 'X';
ISBN[12] = temp;
cout << ISBN;
}
}
else
{
char temp2 = becheck + '0';
ISBN[12] = temp2;
cout <<ISBN;
}
system("pause");
return(0);
}
by Yxy7952 @ 2024-08-28 14:27:55
@imicola @imicola
AC代码楼主看注释:
#include<bits/stdc++.h>
using namespace std;
int main()
{
char ISBN[14]; //创建字符串
cin >> ISBN;
int check = ISBN[12] - '0'; //提取检查值
int arr[20],k=0;//给k赋初始值
for (int i = 0; i < 11; i++)
{
//跳过"-"
if (i == 1 || i == 5 )
{
continue;
}
else
{
arr[k] = ISBN[i] - '0'; //将九个字符记入到数组中
k++;
}
}
int becheck=0; //创建被检查值 赋初始值
for (int j = 1; j < 10; j++)
{
becheck += arr[j - 1]*j; //将九个数字按题目要求分别加进被检查值里
}
becheck %= 11; // 取mod11
if (becheck != 10 && becheck == check) //如果被检查值与检查值相等(被检查值 != 10)时
{
cout << "Right";
}
else if (becheck == 10)
{
if (check == 40) //"X"的ASCII - "0"的ASCII
{
cout << "Right";
}
else
{
char temp = 'X';
ISBN[12] = temp;
cout << ISBN;
}
}
else
{
char temp2 = becheck + '0';
ISBN[12] = temp2;
cout <<ISBN;
}
return(0);
}
by Yxy7952 @ 2024-08-28 14:29:22
@imicola
话说楼主,为什么写了这个
system("pause");
by imicola @ 2024-08-28 16:18:00
@yixingyou
习惯了 www
谢谢
by imicola @ 2024-08-28 16:32:07
@imicola
草,楼主初学用的VScode,int k;
的时候不赋初始值也可以运行,所以楼主我养成了坏习惯
别学楼主,警钟敲烂