O_Egor

var 1

Jun 2nd, 2023 (edited)
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int n;
  9.     cin >> n;
  10.     int ans(0), counter(0);
  11.     int tmp;
  12.  
  13.     for(int i = 0; i < n; ++i)
  14.     {
  15.         cin >> tmp;
  16.         int help = abs(tmp);
  17.         if(help > 9)
  18.         {
  19.             int first_digit(0);
  20.             int last_digit(0);
  21.             last_digit = help % 10;
  22.             while(help > 9)
  23.             {
  24.                 help /= 10;
  25.             }
  26.             first_digit = help;
  27.             if(first_digit == last_digit)
  28.             {
  29.                 if(ans == 0)
  30.                 {
  31.                     ans = tmp;
  32.                 }
  33.                 ++counter;
  34.             }
  35.         }
  36.     }
  37.  
  38.     if(counter)
  39.     {
  40.         cout << ans << ' ' << counter;
  41.     }
  42.     else
  43.     {
  44.         cout << "NO\n";
  45.     }
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment