题解 | #取中值#

取中值

https://www.nowcoder.com/practice/d69e75bb224e4a7785a02b2acc0821c4

#include<cstdio>
#include<vector>
using namespace std;
int main(){
	int n, m;
	scanf("%d %d", &n, &m);
		vector<int>vec1;
		vector<int>vec2;
		vector<int>vec3;
		for (int i = 0; i < n; i++){
			int k;
			scanf("%d", &k);
			vec1.push_back(k);
		}
		for (int i = 0; i < m; i++){
			int k;
			scanf("%d", &k);
			vec2.push_back(k);
		}
		int x1, y1;
		int x2, y2;
		scanf("%d %d", &x1, &y1);
		scanf("%d %d", &x2, &y2);
		for (int i = x1 - 1; i < y1 - 1; i++){
			int s = vec1[i];
			vec3.push_back(s);
		}
		for (int i = x2 - 1; i < y2 - 1; i++){
			int s = vec2[i];
			vec3.push_back(s);
		}
		int j = vec3.size();
		if (j % 2 == 0){
			printf("%d", vec3[j / 2 - 1]);
		}
		if (j % 2 == 1){
			printf("%d", vec3[j / 2]);
		}
	}

全部评论

相关推荐

昨天 11:08
门头沟学院 Java
投递京东等公司9个岗位
点赞 评论 收藏
分享
06-25 09:33
厦门大学 Java
程序员饺子:现在日常估计没啥hc了,等到八月多估计就慢慢有了。双九✌🏻不用焦虑的
投递快手等公司9个岗位
点赞 评论 收藏
分享
不亏是提前批,神仙打架,鼠鼠不配了
站队站对牛:现在92都报工艺岗了
投递韶音科技等公司7个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务