RTW290 @ 2022-10-20 10:55:47
#include<iostream>
using namespace std;
int main(){
char c[13];
int sum=0;int cnt=1;
for(int i=0;i<13;i++){
cin>>c[i];
}
for(int i=0;i<11;i++){
if(c[i]>='0'&&c[i]<='9'){
sum=sum+(c[i]-'0')*cnt;
cnt++;
}
}
sum=sum%11;
char s;
if(sum==10)s='X';
else s=sum+'0';
if(s==c[12])cout<<"Right";
else {
c[12]=s;
for(int i=0;i<13;i++)cout<<c[i];
}return 0;
}
by a2lyaXNhbWUgbWFyaXNh @ 2022-10-20 11:02:34
这边建议C++11正则表达式,简单省事,混乱邪恶
by xiaoooooo @ 2022-10-22 17:34:35
@RTW290
by xiaoooooo @ 2022-10-22 17:44:09
1、这边建议直接输入输出c
2、你输出13个字符干什么
3、c数组应该开15
#include<iostream>
using namespace std;
int main(){
char c[15];
int sum=0;int cnt=1;
cin>>c;
for(int i=0;i<11;i++){
if(c[i]>='0'&&c[i]<='9'){
sum=sum+(c[i]-'0')*cnt;
cnt++;
}
}
sum=sum%11;
char s;
if(sum==10)s='X';
else s=sum+'0';
if(s==c[12])cout<<"Right";
else {
c[12]=s;
cout<<c;
}return 0;
}
by RTW290 @ 2022-10-23 13:30:00
@xiaoooooo 多谢,初学c++