Sicily 1129. ISBN, sicily1129isbn
Question address: 1129. ISBN
Ideas:
This question is relatively simple. You only need to understand the question. Let's explain the question. The question refers to the calculation of the 10 numbers and weights. Based on this and the calculated difference, we can perform Division on 11. If the difference is 10, then add "-X" at the end. If it is not 10, the output "-" is added with the number that can be divisible by the difference.
The Code is as follows:
1 # include <iostream> 2 # include <string> 3 using namespace std; 4 5 int Sum (string x) {6 int sum = 0; 7 int weight = 10; 8 for (int I = 0; I <x. size (); I ++) {9 if (x [I]> = '0' & x [I] <= '9 ') {10 sum + = (x [I]-'0') * (weight --); 11} 12} 13 return sum; 14} 15 16 int main () {17 string test; 18 while (cin> test) {19 int sum = Sum (test); 20 int check_digit = sum % 11 = 0? 0: 11-sum % 11; 21 check_digit = 10? Cout <test <"-X \ n" 22: cout <test <"-" <check_digit <endl; 23} 24 25 return 0; 26}