2020 贝壳笔试题——举重大赛

#include 
#include 
#include 
#include 
#include

using namespace std;

bool good(int a, int b) {
   int max = a >= b ? a : b;
   int min = a < b ? a : b;
   return min >= (0.9 * max);
}

int main() {
   int n;
   long temp[10005];
   cin >> n;
   for (int i = 0; i < n; i++) {
      cin >> temp[i];
   }
   if (n == 2)
   {
      if (good(temp[0], temp[1])) {
         cout << 1 << endl;
      }
      else {
         cout << 0 << endl;
      }
   }
   int sum = 0;
   for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
         if (good(temp[i], temp[j])) {
            sum++;
         }
      }
   }
   cout << sum;
   return 0;
}

 

你可能感兴趣的:(秋招笔试题)