AtCoder Beginner Contest 294 A~C

A - Filter

输入一组数,将偶数输出

#include <bits/stdc++.h>

using namespace std;

const int N = 110;
int a[N];

int main() {
	int n;
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		if(a[i] % 2 == 0)
			cout << a[i] << ' ';
	}
	return 0;
}

B - ASCII Art

给定 h × m h×m h×m矩阵,元素取值为 0 ~ 26,为0输出.,否则输出1~26对应的 A ~ Z。

#include <bits/stdc++.h>

using namespace std;

const int N = 110;
int a[N][N];
int h, w;

int main() {
	cin >> h >> w;
	char ch = 'A';
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			cin >> a[i][j];
			if(a[i][j] == 0) {
				cout << '.';
			}
			else {
				cout << (char)(ch + a[i][j] - 1);
			}
		}
		cout << endl;
	}
	return 0;
}

C - Merge Sequences

A和B都是严格递增的序列,用 l 和 r指针分别维护 A和B数组,如果a[l] < b[r], l++,否则r++。每次操作记录序号。思想与归并排序的合二为一过程类似。

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 10;
int a[N], b[N];
int ta[N], tb[N];//临时数组,标记排序
int n, m;

int main() {
	cin >> n >> m;
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < m; i++) cin >> b[i];

	int l = 0, r = 0, flag = 1;
	while(l < n && r < m) {
		if(a[l] < b[r]) ta[l++] = flag++;
		else tb[r++] = flag++;
	}
	while(l < n) ta[l++] = flag++;//将a中剩余元素标记好
	while(r < m) tb[r++] = flag++;//同理

	for(int i = 0; i < n; i++) cout << ta[i] << ' ';
	cout << endl;
	for(int i = 0; i < m; i++) cout << tb[i] << ' ';
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值