问题描述:
小红拿到了n个物品,每个物品的品质为a。这n个物品中至少有一个真品。
已知所有真品的品质都是相同的,但赝品的品质比真品低。小红想知道,这n个物品中最多有多少赝品。
输入描述:
第一行输入一个正整数n,代表小红拿到的物品数量。第二行输入n个正整数a;,代表每个物品的品质。1
输出描述:
一个整数,代表赝品的数量。
举例:
5
100 100 2 98 100
3
代码结果:
#include
#include
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");
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
