// Do not be confused by this sentence: Each of the first nine digits can take a value between 0 and 9 !!! Unrelated sentence // There are many situations to consider for this question. Just be careful and clarify the situation that needs to be discussed! # Include <iostream> # include <string> # include <algorithm> using namespace STD; int main () {string STR; CIN> STR; int I, j, POs, sum, ans; bool flag; Pos = Str. find ('? '); // If? In this case, the end of a string can be X or another number if (Pos = 9) {sum = 0; flag = false; for (I = 0, j = 10; I <9; I ++, j --) {sum + = (STR [I]-48) * j ;}for (ANS = 0; ans <10; ans ++) {int TMP = sum; TMP + = ans; If (TMP % 11 = 0) {flag = true; break ;}} if (FLAG) cout <ans <Endl; else {sum + = 10; If (sum % 11 = 0) cout <"X" <Endl; else cout <-1 <Endl ;}} // If? If it is not at the end, we can also discuss two cases! Else {If (STR [9] = 'X') {sum = 0; flag = false; for (I = 0, j = 10; I <9; I ++, j --) {If (STR [I] = '? ') Continue; else sum + = (STR [I]-48) * j;} sum + = 10; for (ANS = 0; ans <= 9; ans ++) {int TMP = sum; TMP + = ans * (10-pos); If (TMP % 11 = 0) {flag = true; break ;}} if (FLAG) cout <ans <Endl; else cout <"-1" <Endl;} else {sum = 0; flag = false; for (I = 0, j = 10; I <10; I ++, j --) {If (STR [I] = '? ') Continue; else sum + = (STR [I]-48) * j ;}for (ANS = 0; ans <= 9; ans ++) {int TMP = sum; TMP + = ans * (10-pos); If (TMP % 11 = 0) {flag = true; break ;}} if (FLAG) cout <ans <Endl; else cout <"-1" <Endl ;}} system ("pause") ;}/ * 020110331? 156881111 ?? 20110331103? 11033111x03 */