Lucashuang @ 2021-09-26 21:02:31
#include<bits/stdc++.h>
using namespace std;
int main(){
char a;
int s = 0 , m[9];
cin >> a;
for(int i = 0; i < 10; i++){
if(i < 9){
m[i] = a[i];
}
if((a[i] = getchar()) != "-"){
s += (i + 1) * a[i];
}
}
s = s % 11;
if(a[-1] == s){
cout << "Right" << endl;
} else {
cout << m << s << endl;
}
return 0;
}
by 褚橙 @ 2021-09-26 21:06:22
?? 编译没过??
by ssdmr @ 2021-09-26 21:07:33
应该有a[]吧?
by ssdmr @ 2021-09-26 21:08:13
错误都是显示在a[ ]上
by ssdmr @ 2021-09-26 21:09:26
@Lucashuang 应该是a的问题
by int64 @ 2021-09-26 21:09:59
@Lucashuang 应该定义 char 数组而不是单个 char 变量。
by int64 @ 2021-09-26 21:10:25
还有,
if(a[-1] == s){
是个什么鬼?
by ssdmr @ 2021-09-26 21:11:10
@Lucashuang 编译失败
/tmp/compiler_s9kll_zv/src: 在函数‘int main()’中:
/tmp/compiler_s9kll_zv/src:9:23: 错误:‘char[int]’用作数组下标类型无效 m[i] = a[i]; ^ /tmp/compiler_s9kll_zv/src:11:16: 错误:‘char[int]’用作数组下标类型无效 if((a[i] = getchar()) != "-"){ ^ /tmp/compiler_s9kll_zv/src:12:31: 错误:‘char[int]’用作数组下标类型无效 s += (i + 1) * a[i]; ^ /tmp/compiler_s9kll_zv/src:16:12: 错误:‘char[int]’用作数组下标类型无效 if(a[-1] == s){ ^
by 违规用户名gAGt8$%z @ 2021-09-26 21:11:18
@Lucashuang 正解
#include<bits/stdc++.h>
using namespace std;
int main()
{
char a[15];
int i,sum=0,k=0,m=1;
cin>>a;
for(i=1;i<=11;i++)
{
if(a[k]-48<10&&a[k]-48>-1)
{
sum+=(a[k]-48 )*m;
m++;
}
k++;
}
if(a[12]=='X'){
if(sum%11==10){
cout<<"Right";
}
else{
for(i=0;i<=11;i++)
{
cout<<a[i];
}
if(sum%11==10)
cout<<'X';
else
cout<<sum%11;
}
}
else
{
if(sum%11==a[12]-48)
{
cout<<"Right";
}
else
{
for(i=0;i<=11;i++)
{
cout<<a[i];
}
if(sum%11==10)
cout<<'X';
else
cout<<sum%11;
}
}
return 0;
}
by Lucashuang @ 2021-09-26 21:12:58
大师,我悟了!!!感谢?