Statistics on the number of students with the same score and the number of ACM students

Source: Internet
Author: User

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.


 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.