Poj 2190 ISBN

Source: Internet
Author: User
// 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 */

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.