A_liusizhe @ 2024-08-15 08:43:56
#include <bits/stdc++.h>
using namespace std;
char a[12],ans1,ans2;
int sum;
int main() {
cin>>a>>ans1;
for(int i=1; i<=a.length(); i++) sum+=((int)a[i]-48)*i;
ans2=(char)sum%11+'0';
if(ans2==(char)('0'+10)) ans2='X';
if(ans1==ans2) cout<<"Right";
else
cout<<a[1]<<'-'<<a[2]<<a[3]<<a[4]<<'-'<<a[5]<<a[6]<<a[7]<<a[8]<<a[9]<<'-'<<ans2;
return 0;
}
by medal_dreams @ 2024-08-15 08:51:01
如果直接输入不应该从0开始遍历吗 @A_liusizhe
by medal_dreams @ 2024-08-15 08:58:38
你的代码改好了,应该是:
#include <bits/stdc++.h>
using namespace std;
char a[12],ans1,ans2;
int sum;
int main() {
cin>>a;
int k=strlen(a);
int p=1;
ans1=a[k-1];
for(int i=0; i<k-1; i++)
if(isdigit(a[i]))
sum+=(a[i]-'0')*p,p++;
ans2=sum%11+'0';
if(ans2==(char)('0'+10))
ans2='X';
if(ans1==ans2)
cout<<"Right";
else
{
for(int i=0;i<k-1;i++)
{
cout<<a[i];
}
cout<<ans2;
}
return 0;
}
``` @[A_liusizhe](/user/1266815)
by medal_dreams @ 2024-08-15 09:00:24
求关
by A_liusizhe @ 2024-08-15 09:23:34
@medal_dreams 谢谢
by medal_dreams @ 2024-08-15 09:29:18
@A_liusizhe 不客气