2012zxt @ 2022-07-03 13:16:16
#include<bits/stdc++.h>
using namespace std;
int sum,cnt,n;
string s;
void print()
{
for(int i=0;i<n-1;i++)
{
cout<<s[i];
}
return ;
}
int main()
{
cin>>s;
n=s.size();
for(int i=0;i<n-1;i++)
{
if(s[i]=='-')
continue;
cnt++;
sum+=cnt*s[i];
}
cout<<sum<<endl;
if(sum%11==10)
{
if(s[n-1]=='X')
{
cout<<"Right";
return 0;
}
print();
cout<<"X";
}
if(s[n-1]!=sum%11)
{
print();
cout<<sum%11;
return 0;
}
cout<<"Right";
return 0;
}
by After_light @ 2022-07-03 13:18:07
i<n
by After_light @ 2022-07-03 13:21:03
@2012zxt 第17行
by 2012zxt @ 2022-07-03 13:29:33
改了一下
#include<bits/stdc++.h>
using namespace std;
int sum,cnt,n;
string s,e;
void print()
{
for(int i=0;i<n-1;i++)
{
cout<<s[i];
}
return ;
}
int main()
{
cin>>e;
n=s.size();
s=e;
for(int i=0;i<n-1;i++)
{
if(s[i]=='-')
continue;
s[i]-='0';
cnt++;
sum+=cnt*s[i];
}
if(sum%11==10)
{
if(s[n-1]=='X')
{
cout<<"Right";
return 0;
}
print();
cout<<"X";
return 0;
}
if(s[n-1]!=sum%11)
{
print();
cout<<sum%11;
return 0;
}
else
{
cout<<"Right";
return 0;
}
return 0;
}
by uid_647775 @ 2022-07-03 13:38:33
22行
sum+=cnt*(s[i]-'0');
35行也是
by uid_647775 @ 2022-07-03 13:39:06
@2012zxt
by Ruiqun2009 @ 2022-07-03 13:46:41
@2012zxt string
的原型是这样的:
namespace std {
typedef basic_string<char> string;
}
也就是说,string
里存的东西是char
。