Guest User

Untitled

a guest
Nov 19th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <locale.h>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. setlocale(LC_ALL, "Rus");
  9. int sum = 0;
  10. int p = 0;
  11. int check = 0;
  12. int x = 0;
  13. int unknown = 0; //пропущенный символ
  14. string card;
  15. getline(cin, card);for(int i = 0; i < card.size(); i++){
  16. cout<<card[i];
  17. }
  18. for(int i = card.size() - 1; i >= 0; i--) {
  19. char ch = card[i];
  20. if(ch >= '0' && ch <= '9'){
  21. p = (i % 2 == 0 ? 2 : 1);
  22. char s = card[i] - '0';
  23. sum += (s * p > 9 ? (s * p) - 9 : s * p);
  24. } else {
  25. if(ch == 'x')
  26. check = (i % 2 == 0 ? 2 : 1);
  27. }
  28. }
  29. if(check > 0){
  30. cout<<"begin"<<endl;
  31. for(int i = 0; i < 9; i++){
  32. unknown = (x * check > 9 ? (x * check) - 9 : x * check);
  33. if((sum + unknown) % 10 == 0){
  34. cout << "sum = " << sum + unknown << endl << "number = " <<x << endl;
  35. break;
  36. } else x++;
  37. }
  38. } else cout<<(sum % 10 == 0 ? "It's right." : "It's wrong.");
  39. return 0;
  40. }
Add Comment
Please, Sign In to add comment