https://www.luogu.com.cn/problem/P1055
示例
输入:0-670-82162-4
输出:Right
输入:0-670-82162-0
输出:0-670-82162-4
思路
模拟
代码
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
int s_tot(0), g_num(0), k(1);
string ans;
string res;
char ch = getchar();
while (1) {
if (res.length() == 13) break;
if (isdigit(ch) && g_num < 3) {
s_tot += k * (ch - 48);
k++;
}
if (g_num < 3) ans += ch;
if (ch == '-') g_num++;
res += ch;
ch = getchar();
}
ans += (s_tot % 11 > 9) ? 'X' : (char)((s_tot % 11) + 48);
cout << (ans == res ? "Right" : ans) << endl;
return 0;
}