1 #include <iostream> 2 #include <algorithm> 4 #include <array> 5 6 int main() { 7 std::array<int, 9> ISBN{}; 8 char c{}; 9 int lenth{},sigl{-1}; 10 11 for(int i{};i <= 10;i++){ 12 std::cin.get(c); 13 if (c != '-') { 14 ISBN[lenth] = static_cast<int>(c)-48; 15 lenth++; 16 } 17 } 18 std::cin.get(c); 19 std::cin.get(c); 20 if (c >= '0' && c <= '9') { 21 sigl = static_cast<int>(c) - 48; 22 }else{ 23 sigl = 10; 24 } 25 26 int sum{}; 27 for (int i{}; i < 9; i++) { 28 sum += ISBN[i] * (i + 1); 29 } 30 sum = sum % 11; 31 if (sum == sigl) { 32 std::cout << "Right"; 33 } 34 else { 35 for (int i{}; i < 9; i++) { 36 std::cout << ISBN[i]; 37 if (i == 0 || i == 3 || i == 8) { 38 std::cout << '-'; 39 } 40 } 41 if (sum != 10) { 42 std::cout << sum; 43 } 44 else { 45 std::cout << "X"; 46 } 47 } 48 }
标签:std,ISBN,int,201312,sum,sigl,C++,include From: https://www.cnblogs.com/n00b/p/16892061.html