小红拿到了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("%dn",Defective_Product_Quantity);system("pause");
}
本文发布于:2024-01-31 19:32:11,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170670073230844.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |