652. wzt的树

编程入门 行业动态 更新时间:2024-10-23 13:36:42

652. <a href=https://www.elefans.com/category/jswz/34/1707971.html style=wzt的树"/>

652. wzt的树

#include<stdio.h>
#include<algorithm>
using namespace std;//使用sort函数
int main(){int t;scanf("%d",&t);for(;t>0;t--){int n,q;scanf("%d",&n);int h[n]={0};int i,count;int xi;for(i=0;i<n;i++){scanf("%d",&h[i]);}sort(h,h+n);//使数组从小到大排列scanf("%d",&q);for(;q>0;q--){scanf("%d",&xi);for(count=n,i=0;i<n;i++){//注意count=nif (h[i]>xi){count=i;break;}}printf("%d\n",count);}}return 0;
}

sort与cmp搭配使用可以使数组从大到小排列:

#include<stdio.h>
#include <algorithm>
using namespace std;
bool cmp(int x,int y)
{return x>y;
}
//bool为布尔类型,只有一个字节,取值0(false)、1(true)。
int main()
{int a[5];printf("输入:");for(int i=0;i<5;i++){scanf("%d",&a[i]);}//sort(a,a+5);//从小到大排序 sort(a,a+5,cmp);//从大到小排序 printf("默认排序结果:");for(int i=0;i<5;i++){printf("%d ",a[i]);}return 0;
}

更多推荐

652. wzt的树

本文发布于:2024-03-04 02:05:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1707970.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:wzt

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!