Statistics on the number of students with the same score and the number of ACM students
Count the number of students with the same score: [Problem description] reads the scores of N students and outputs the number of students with a given score. [Requirement] [data input] The test input contains several test cases. The format of each test case is 1st rows: N 2nd rows: scores of N students, two Adjacent numbers are separated by a space. Row 3rd: the input ends when the given score is N = 0. Where N does not exceed 1000, and the score is an integer (including) between 0 and 100. [Data output] for each test case, the number of students with a given score is output. [Sample output] 380 60 9060285 660560 75 90 55 75750 [sample output] 102
Code:
# Include <iostream> using namespace std; int main () {int N, I, n; do {cin> N; // enter N; if (N = 0 | N> 1000 | N <0) // end when N = 0, and ensure that N is within []; break; else {int a [N], k = 0; // defines an array record score. The initial number of people who have obtained this score is 0. for (I = 0; I <N; ++ I) cin> a [I]; // enter the scores of N students. cin> n; // give a score for (I = 0; I <N; ++ I) {if (a [I] = n) // k ++ when the score of a student is equal to the given score; // The number of people who have obtained the score plus 1} cout <k <endl; // output the number of people who obtained the score;} cout <endl;} while (1); // when N is not 0 and ~ Keep loop within 1000. Return 0 ;}
Running result:
Learning Experience:
The array is quite useful. I forgot how to record the multiple numbers that need to be recorded before learning the array...
Originally, the program can only be ended when N = 0, and the input N value is not within [1, I have previously done this and I will not write any more here.