나는 이렇게 학습한다/Algorithm & SQL

1126. How good are you really?

daco2020 2022. 11. 26. 23:32
반응형

There was a test in your class and you passed it. Congratulations! But you're an ambitious person. You want to know if you're better than the average student in your class.

You receive an array with your peers' test scores. Now calculate the average and compare your score!

Return True if you're better, else False!

Note:

Your points are not included in the array of your class's points. For calculating the average point you may add your point to the given array!



Solution:

bool betterThanAverage(List<int> classPoints, int yourPoints) {
  int a = sum_point(classPoints);
  int b = classPoints.length;
  double result = a / b;
  return result < yourPoints;
}

int sum_point(List<int> classPoints) {
  int result = 0;
  for (int i in classPoints) {
    result += i;
  }
  return result;
}


반응형

'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글

1128. Hex to Decimal  (0) 2022.11.28
1127. Two to One  (0) 2022.11.27
1125. MakeUpperCase  (0) 2022.11.25
1124. Beginner Series #2 Clock  (0) 2022.11.24
1123. L1: Set Alarm  (0) 2022.11.24