-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoffset
More file actions
100 lines (84 loc) · 2.22 KB
/
offset
File metadata and controls
100 lines (84 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
문제
5x5 2차원 배열이 주어질 때 어떤 원소가 상하좌우에 있는 원소보다 작을 때 해당 위치에 * 을 표시하는 프로그램을 작성하시오. 경계선에 있는 수는 상하좌우 중 존재하는 원소만을 비교한다.
입력
5x5 행렬의 정보가 25 개의 수로 주어진다. 각 수는 0 에서 9 사이 수이다.
출력
*를 포함한 행렬을 출력예의 형식으로 출력한다.
예제 입력
3 4 1 4 9
2 9 4 5 8
9 0 8 2 1
7 0 2 8 4
2 7 2 1 4
예제 출력
3 4 * 4 9
* 9 4 5 8
9 0 8 2 *
7 0 2 8 4
* 7 2 * 4
#include <stdio.h>
int main(){
int offset[5][5];
for(int i=0;i<5;i++){
for(int j=0;j<5;j++){
scanf("%d ",&offset[i][j]);
}
}
if(offset[0][0]<offset[0][1] && offset[0][0]<offset[1][0]){
offset[0][0]=-1;
}
if(offset[0][4]<offset[0][3] && offset[0][4]<offset[1][4]){
offset[0][4]=-1;
}
if(offset[4][0]<offset[3][0] && offset[4][0]<offset[4][1]){
offset[4][0]=-1;
}
if(offset[4][4]<offset[3][4] && offset[4][4]<offset[4][3]){
offset[4][4]=-1;
}
for(int jj=1;jj<4;jj++){
if((offset[0][jj]<offset[0][jj-1]) && (offset[0][jj]<offset[0][jj+1])){
if(offset[0][jj]<offset[1][jj]){
offset[0][jj]=-1;
}
}
if((offset[4][jj]<offset[4][jj-1]) && (offset[4][jj]<offset[4][jj+1])){
if(offset[4][jj]<offset[3][jj]){
offset[4][jj]=-1;
}
}
}
for(int ii=1;ii<4;ii++){
if((offset[ii][0]<offset[ii-1][0]) && (offset[ii][0]<offset[ii+1][0])){
if(offset[ii][0]<offset[ii][1]){
offset[ii][0]=-1;
}
}
if((offset[ii][4]<offset[ii-1][4]) && (offset[ii][4]<offset[ii+1][4])){
if(offset[ii][4]<offset[ii][3]){
offset[ii][4]=-1;
}
}
}
for(int iii=1;iii<4;iii++){
for(int jjj=1;jjj<4;jjj++){
if((offset[iii][jjj]<offset[iii-1][jjj]) && (offset[iii][jjj]<offset[iii+1][jjj])){
if((offset[iii][jjj]<offset[iii][jjj-1]) && (offset[iii][jjj]<offset[iii][jjj+1])){
offset[iii][jjj]=-1;
}
}
}
}
for(int k=0;k<5;k++){
for(int s=0;s<5;s++){
if(offset[k][s]==-1){
printf("* ");
}
else{
printf("%d ",offset[k][s]);
}
}
printf("\n");
}
return 0;
}