csansoon

P6.15 P35957 Middle digits

Nov 7th, 2018
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. bool isEven(int n) {
  5.     if(n%2==0) return true;
  6.     else return false;
  7. }
  8.  
  9.  
  10. int digits(int n) {
  11.     int d=1;
  12.     while (n/10!=0) {
  13.         n/=10;
  14.         d++;
  15.     }
  16.     return d;
  17. }
  18.  
  19.  
  20. int midNumber(int n) {
  21.     for (int i=(digits(n)/2);i>0;i--) n=n/10;
  22.     return n%10;
  23. }
  24.  
  25.  
  26.  
  27. int main() {
  28.     int plays,A,B,result=0;
  29.     cin>>plays;
  30.     cin>>A;
  31.     if (not isEven(digits(A))) {
  32.         for (int i=(plays-1);i>0;i--) {
  33.             cin>>B;
  34.             if (isEven(digits(B)) or midNumber(A)!=midNumber(B)) {
  35.                 result=1;
  36.                 break;
  37.             }
  38.             cin>>A;
  39.             if (isEven(digits(A)) or midNumber(A)!=midNumber(B)) {
  40.                 result=2;
  41.                 break;
  42.             }
  43.         }
  44.         if (result==0) {
  45.             cin>>B;
  46.             if ((isEven(digits(B)) or midNumber(A)!=midNumber(B)) and result==0) result=1;
  47.         }
  48.     }
  49.     else result=2;
  50.    
  51.     switch(result) {
  52.         case 1:
  53.             cout<<"A"<<endl;
  54.             break;
  55.         case 2:
  56.             cout<<"B"<<endl;
  57.             break;
  58.         case 0:
  59.             cout<<"="<<endl;
  60.             break;
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment