freee Programming Contest 2022(AtCoder Beginner Contest 264) 题解 (A~D)

A - “atcoder”.substr()

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 100 100 100 points

Problem Statement

Print the L L L-th through R R R-th characters of the string atcoder.

Constraints

L L L and R R R are integers.
1 ≤ L ≤ R ≤ 7 1≤L≤R≤7 1LR7

Input

Input is given from Standard Input in the following format:

L L L R R R

Output

Print the answer.

题面翻译

给定左右边界 L L L R R R,求截取 [ L , R ] [L,R] [L,R]后的atcoder字符串。

Sample Input 1

3 6

Sample Output 1

code

The 3 3 3-rd through 6 6 6-th characters of atcoder are code.

Sample Input 2

4 4

Sample Output 2

o

Sample Input 3

1 7

Sample Output 3

atcoder

题解部分

我们用一个string类型变量记录一下字符串atcoder
再用一重循环输出区间内的字符即可。

#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;

int main () {
   
	string str = " atcoder";
	int l, r;
	scanf ("%d %d", &l, &r);
	for (int i = l; i <= r; i ++) {
   
		printf ("%c", str[i]);
	}
	return 0;
}

B - Nice Grid

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 200 200 200 points

Problem Statement

Print the color of the cell at the R-th row from the top and C-th column from the left in the following grid with 15 vertical rows and 15 horizontal columns.

Constraints

1 ≤ R , C ≤ 15 1≤R,C≤15 1R,C15
R R R and C C C are integers.

Input

Input is given from Standard Input in the following format:

R R R C C C

Output

In the grid above, if the color of the cell at the R R R-th row from the top and C C C-th column from the left is black, then print black; if the cell is white, then print white. Note that the judge is case-sensitive.

题面翻译

给出坐标 ( R , C ) (R,C) (R,C),判断上图第 R R R行,第 C C C列的颜色。

Sample Input 1

3 5

Sample Output 1

black

In the grid above, the cell at the 3 3 3-rd row from the top and 5 5 5-th column from the left is black. Thus, black should be printed.

Sample Input 2

4 5

Sample Output 2

white

In the grid above, the cell at the 4 4 4-th row from the top and 5 5 5-th column from the left is white. Thus, white should be printed.

题解部分

我们可以用用两重循环标记整个图的颜色,再输出对应字符串即可。

#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;

bool fl[20][20];

int main () {
   
	int a, b;
	scanf ("%d %d", &a, &b);
	for (int i = 1; i <= 7; i += 2) {
   
		for (int j = i; j <= 15 - i + 1; j ++) {
   //每一圈正方形的上、左边
			fl[i][j] = 1;
			fl[j][i] = 1;
		}
		for (int j = 15 - i + 1; j >= i; j --) {
   //每一圈正方形的下、右边
			fl[15 - i + 1][j] = 1;
			fl[j][15 - i + 1] = 1;
		}
	}
	printf ("%s", fl[a][b] == 1 ? "black" : "white");
	return 0;
}

C - Matrix Reducing

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 300 300 300 points

Problem Statement

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值