9-degree OJ 1018 count the number of students with the same score, oj1018
Question 1018: count the number of students with the same score
Time Limit: 1 second
Memory limit: 32 MB
Special question: No
Submit: 6337
Solution: 3419
-
Description:
-
Reads the scores of N students and outputs the number of students who have obtained a given score.
-
Input:
-
The test input contains several test cases. The format of each test case is
Row 3: N
Row 2nd: scores of N students. Two Adjacent numbers are separated by a space.
Row 3rd: Given score
When N = 0 is read, the input ends. Where N does not exceed 1000, and the score is an integer (including) between 0 and 100.
-
Output:
-
For each test case, the number of students with a given score is output.
-
Sample input:
-
380 60 9060285 660560 75 90 55 75750
-
Sample output:
-
102
#include<stdio.h>int a[1001];int main(int argc, char *argv[]){ int N; while(~scanf("%d",&N)) { if(N==0)return 0; for(int i=0;i<N;++i) scanf("%d",&a[i]); int num; int cnt=0; scanf("%d",&num); for(int i=0;i<N;++i) if(a[i]==num) { cnt++; } printf("%d\n",cnt); } return 0;} /************************************************************** Problem: 1018 User: kirchhoff Language: C Result: Accepted Time:10 ms Memory:916 kb****************************************************************/