marmotgreatagain @ 2024-06-27 20:51:19
求大佬看看帮忙debug
using namespace std;
int main() { char ch; string a; cin >> a; int c[10], i = 0, sum = 0; for (auto b : a) { if (isdigit(b)) { c[i] = b; i++; } } for (int x = 0; x < 9; x++) { sum = sum + c[x] * (x + 1); } sum %= 11; if (sum == c[10]) { cout << "right"; } else if (sum == 10) { ch = 'X'; a.pop_back(); a.push_back(ch); } else { a.pop_back(); ch = sum + '0'; a.push_back(ch); cout << a; }
return 0;
}```cpp
using namespace std;
int main() { char ch; string a; cin >> a; int c[10], i = 0, sum = 0; for (auto b : a) { if (isdigit(b)) { c[i] = b; i++; } } for (int x = 0; x < 9; x++) { sum = sum + c[x] * (x + 1); } sum %= 11; if (sum == c[10]) { cout << "right"; } else if (sum == 10) { ch = 'X'; a.pop_back(); a.push_back(ch); } else { a.pop_back(); ch = sum + '0'; a.push_back(ch); cout << a; }
return 0;
}
by HEROBRINEH @ 2024-06-27 20:52:38
AC 我的代码
#include <bits/stdc++.h>
using namespace std;
int main()
{
string i;
cin >> i;
int x;
x = i[0] - '0'+ (i[2] - '0') * 2 + (i[3] - '0') * 3 + (i[4] - '0') * 4 + (i[6] - '0') * 5 + (i[7] - '0') * 6 + (i[8] - '0') * 7 + (i[9] - '0') * 8 + (i[10] - '0') * 9;
x = x % 11;
if (i[12] - '0' == x || (i[12] == 'X' && x == 10))
cout << "Right" << endl;
else
{
for (int l = 0; l <= 11; l++)
cout << i[l];
if (x == 10)
cout << "X" << endl;
else
cout << x << endl;
}
return 0;
}
by marmotgreatagain @ 2024-06-27 20:57:32
@HEROBRINEH 大佬请问我的能改改吗
by MuLinnnnn @ 2024-06-27 21:08:32
@marmotgreatagain 求您先把Latex修一修、
by jubaoyi2011 @ 2024-06-27 21:08:45
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin >> s;
int sum = 0;
int cnt = 0;
for (int i=0; i<s.size()-1; i++) {
if (s[i]!='-') {
sum += (s[i]-'0') * ++cnt;
}
}
int m = sum % 11;
char c;
if (m<10) c = m + '0';
else c = 'X';
if (s[s.size()-1] == c) cout << "Right";
else {
s[s.size()-1] = c;
cout << s;
}
return 0;
}
另一种思路,希望能给你启发 @marmotgreattagain
by jubaoyi2011 @ 2024-06-27 21:09:25
@marmotgreatagain
by marmotgreatagain @ 2024-06-27 21:17:50
#include<iostream>
#include<string>
#include<cctype>
using namespace std;
int main()
{
char ch;
string a;
cin >> a;
int c[10], i = 0, sum = 0;
for (auto b : a)
{
if (isdigit(b))
{
c[i] = b;
i++;
}
}
for (int x = 0; x < 9; x++)
{
sum = sum + c[x] * (x + 1);
}
sum %= 11;
if (sum == c[10])
{
cout << "right";
}
else if (sum == 10)
{
ch = 'X';
a.pop_back();
a.push_back(ch);
}
else
{
a.pop_back();
ch = sum + '0';
a.push_back(ch);
cout << a;
}
return 0;
}
@Algophitronrhythm_
by marmotgreatagain @ 2024-06-27 21:22:18
@jubaoyi2011 感谢感谢