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 1≤L≤R≤7
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 1≤R,C≤15
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