題目分析:
依次輸入成績到數組裡,注意數組大小為1000,再比對給定成績,得出人數。
源代碼:
[cpp]
#include <iostream>
using namespace std;
int main()
{
int n;
while (cin>>n)
{
if (n == 0)
{
break;
}
int a[1000] = {0};
for (int i = 0; i < n; i++)
{
cin>>a[i];
}
int grade;
cin>>grade;
int j = 0;
for (int i = 0; i < n; i++)
{
if (grade == a[i])
{
j++;
}
}
cout<<j<<endl;
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int n;
while (cin>>n)
{
if (n == 0)
{
break;
}
int a[1000] = {0};
for (int i = 0; i < n; i++)
{
cin>>a[i];
}
int grade;
cin>>grade;
int j = 0;
for (int i = 0; i < n; i++)
{
if (grade == a[i])
{
j++;
}
}
cout<<j<<endl;
}
return 0;
}