统计同成绩学生人数

题目描述

读入N名学生的成绩,将获得某一给定分数的学生人数输出。

输入描述:

测试输入包含若干测试用例,每个测试用例的格式为
第1行:N
第2行:N名学生的成绩,相邻两数字用一个空格间隔。
第3行:给定分数
当读到N=0时输入结束。其中N不超过1000,成绩分数为(包含)0到100之间的一个整数。

输出描述:

对每个测试用例,将获得给定分数的学生人数输出。

输入

3
80 60 90
60
2
85 66
0
5
60 75 90 55 75
75
0

输出

1
0
2

代码

#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int i,N,find,cnt=0;
    while(cin>>N){
        cnt=0;
        int score[1001];
        if(N==0)
            break;
        for(i=0;i<N;i++)
            cin>>score[i];
        cin>>find;
        for(i=0;i<N;i++)
            if(score[i]==find)
                cnt++;
        cout<<cnt<<endl;
    }
    return 0;
}

方法二:

#include<iostream>
using namespace std;
int main(){
    int i,N,find,cnt=0;
    while(cin>>N&&N){
        int score[101]={0};
        cnt=0;
        for(i=0;i<N;i++){
            cin>>find;
            score[find]++;
        }
        cin>>find;
        cout<<score[find]<<endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值