0
点赞
收藏
分享

微信扫一扫

今日学习在线编程题:指定集合

云卷云舒xj 2022-04-27 阅读 62

 题目来源:码蹄集

​​​​​​https://matiji.net/exam/brushquestion/159/778/B3FCFEC101BD05189BB74D522E019504

时间限制:1000ms
内存限制:65535kb
 

题目描述:某数组含有N个元素,输出那些数字来自集合{4,5,6}的元素,按原序。没有 就输出-1。
 

输入格式:第一行输入数组长度N,第二行输入数组元素,整型,空 格分隔。
输出格式:输出整型,空格分隔。​​​​​​​
 

输入样例:4

                  1 2 3 4
输出样例:4

参考程序

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int n;
inline void init(){
	scanf("%d",&n);
	int cnt=0,x;
	for(int i=1;i<=n;++i){
		scanf("%d",&x);
		if(x==4||x==5||x==6){
			++cnt;printf("%d ",x);
		}
	}
	if(!cnt){
		puts("-1");
	}
}

int main(){
	init();
	return 0;
}

举报

相关推荐

0 条评论