特别注意'X': (1) 当问号出现在末尾,它可能是0~9,X (2) 当问号出现在其它位置,它可能是0~9,不可以是X #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <string> #include <bitset> using namespace std; int main() { char str[20]; gets(str); int q; int sum = 0; for (int i = 0; i < 10; ++ i) { switch (str[i]) { case '?': q = 10 - i; break; case 'X': sum += (10 - i) * 10; break; default: sum += (10 - i) * (str[i] - '0'); break; } } int num = 0; while ((sum + num * q) % 11 && num <= 10) ++ num; if (num < 10) cout << num << endl; else if (num == 10 && q == 1) cout << "X" << endl; else cout << "-1" << endl; return 0; }