codecolorThD @ 2024-01-22 21:41:26
代码如下,只有1,4,7,过了,没过的都是最后一位输出错误。
#include <iostream>
#include <string>
using namespace std;
int main() {
string str;
int all = 0,j = 0;
cin >> str;
for (int i = 0; i <= 11; i++) {
if (str[i] != '-') {
j++;
all += int(str[i] - '0') * j;
}
}
all %= 11;
if (all == (str[12] - '0')||(all == 10 && str[12] == 'X'))
cout << "Right";
else if( all == 10)
cout << str << '\b' << 'X';
else
cout << str << '\b' << all;
return 0;
}
by FarmerDrone @ 2024-01-22 22:01:07
'\b'这种偷鸡的写法是不行的 这样就行了
#include <iostream>
#include <string>
using namespace std;
int main() {
string str;
int all = 0,j = 0;
cin >> str;
for (int i = 0; i <= 11; i++) {
if (str[i] != '-') {
j++;
all += int(str[i] - '0') * j;
}
}
all %= 11;
if (all == (str[12] - '0')||(all == 10 && str[12] == 'X'))
cout << "Right";
else if( all == 10)
{
for (int i = 0; i <= 11; i++)
cout << str[i];
cout << "X" << endl;
}
else
{
for (int i = 0; i <= 11; i++)
cout << str[i];
cout << all << endl;
}
return 0;
}
by codecolorThD @ 2024-01-23 21:39:13
@xuyao35 谢谢,解决了。看来对于洛谷的机制还是得好好研究一下。