ZeroJudge A148: You Cannot Pass?!

You took N written exams, and each subject has a maximum score of 100. The teacher said that if your average score is greater than 59, you pass.

Sample Inputs/Outputs

Sample Input(s)Sample Output(s)
EOF input: Each input starts with a number N, followed by N positive integers.If you fail, output "yes"; otherwise, output "no."
1 60
3 0 80 75
5 61 61 61 61 55
no
yes
no

Thought Process

The first number on the first line is 1, which means the next input will be 1 number. Since 60 > 59, the output is "no."

On the second line, the first number is 3, indicating the next input will be 3 numbers: 0, 80, and 75. The average of these three numbers is 51.6. Since 51.6 is not greater than 59, the output is "yes."

On the third line, the first number is 5, and the next input will be 5 numbers. The average is 59.8. Since 59.8 > 59, the output is "no."

Sample Code-ZeroJudge A148: You Cannot Pass?!

#include <iostream>
using namespace std;

int main() {
  float N;
  while (cin >> N)
    {
      float sum = 0;
      for (int i = 0; i<N; i++)
        {
          float tmp;
          cin >> tmp;
          sum += tmp;
        }
      if (sum/N > 59) cout << "no" << endl;
      else cout << "yes" << endl;
    }
}

//ZeroJudge A148
//Dr. SeanXD

Comments