问题描述:
小红拿到了n个物品,每个物品的品质为a。这n个物品中至少有一个真品。
已知所有真品的品质都是相同的,但赝品的品质比真品低。小红想知道,这n个物品中最多有多少赝品。
输入描述:
第一行输入一个正整数n,代表小红拿到的物品数量。第二行输入n个正整数a;,代表每个物品的品质。1<n≤10^5;1≤ ai ≤10 ^9
输出描述:
一个整数,代表赝品的数量。
举例:
5
100 100 2 98 100
3
代码结果:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int n;
int a[100000];
int Biggest,Good_Product_Quantity=0;
int Defective_Product_Quantity=0;
scanf("%d",&n);
for(int i=0;i<n;i++)//导入商品并寻找最大值个数
{
scanf("%d",&a[i]);
if(i==0)//第一个数
{
Biggest=a[i];
Good_Product_Quantity=1;
}
else//第一个以后的数
{
if(a[i]>Biggest)//更大则刷新
{
Biggest=a[i];
Good_Product_Quantity=1;
}
else if(a[i]==Biggest)//相等则计数
{
Good_Product_Quantity++;
}
else{};//更小则忽视
}
}
Defective_Product_Quantity=n-Good_Product_Quantity;//除却良品外均为次品
printf("%d\n",Defective_Product_Quantity);
system("pause");
}