Quiz 13
===
# [A]
## Explanation
## Code
```c=
#include <stdio.h>
int main(){
int arr[500][500];
char end;
int row, col;
int srow, scol, erow, ecol;
int printed = 0;
while(1){
scanf("%c", &end);
while(!((end == '*') || ((end >= '0') && (end <= '9')))){ //不得到空白及換行
scanf("%c", &end);
}
if(end == '*'){
break;
}
row = (int)end - (int)'0';
scanf("%c", &end);
if(end != ' '){ //若row為二位數
row = row * 10 + (int)end - (int)'0';
}
scanf("%d %d %d %d %d", &col, &srow, &scol, &erow, &ecol);
for(size_t i=0; i<row; i++){
for(size_t j=0; j<col; j++){
scanf("%d", &arr[i][j]);
}
}
if(printed){
puts("");
}
else{
printed = 1;
}
for(size_t i=srow; i<=erow; i++){
for(size_t j=scol; j<=ecol; j++){
if(j == ecol){
printf("%d\n", arr[i][j]);
}
else{
printf("%d ", arr[i][j]);
}
}
}
}
return 0;
}
```
# [B]
## Explanation
## Code
```c=
#include <stdio.h>
int main(){
int arr[500][500];
char end;
int row, col, s_row, s_col, step;
int printed = 0;
int max;
while(1){
scanf("%c", &end);
while(!((end == '*') || ((end >= '0') && (end <= '9')))){
scanf("%c", &end);
}
if(end == '*'){
break;
}
row = (int)end - (int)'0';
scanf("%c", &end);
if(end != ' '){
row = row*10 + (int)end - '0';
}
scanf("%d %d %d %d", &col, &s_row, &s_col, &step);
for(size_t i=0; i<row; i++){
for(size_t j=0; j<col; j++){
scanf("%d", &arr[i][j]);
}
}
if(printed){
puts("");
}
else{
printed = 1;
}
for(size_t i=0; i<row; i+=step){
if(i+s_row > row){
break;
}
for(size_t j=0; j<col; j+=step){
if(j+s_col > col){
break;
}
max = -1;
for(size_t sight_i=i; sight_i<(i+s_row); sight_i++){
for(size_t sight_j=j; sight_j<(j+s_col); sight_j++){
if(arr[sight_i][sight_j] > max){
max = arr[sight_i][sight_j];
}
}
}
if(j+step+s_col > col){
printf("%d\n", max);
}
else{
printf("%d ", max);
}
}
}
}
}
```
# [C]
## Explanation
## Code
```c=
#include <stdio.h>
#include <stdlib.h>
int main(){
int start, height, end;
int *blocks;
int s_block, e_block;
int cases, components;
scanf("%d", &cases);
for(int case_count=1; case_count<=cases; case_count++){
scanf("%d", &components);
blocks = calloc(10001, sizeof(int));
s_block = 10000;
e_block = 0;
for(int component=0; component<components; component++){
scanf("%d %d %d", &start, &height, &end);
if(start < s_block){
s_block = start;
}
if(end > e_block){
e_block = end;
}
for(int i=start; i<end; i++){
if(blocks[i] < height){
blocks[i] = height;
}
}
}
printf("Case %d:", case_count);
height = 0;
for(int i=s_block; i<=e_block+1; i++){
if((i == s_block) || (blocks[i] != height)){
height = blocks[i];
printf(" %d %d", i, height);
}
}
puts("");
free(blocks);
}
}
```
###### tags: `程設一quiz`