forked from DPrinceKumar/HacktoberFest2020-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3d_surface_area.c
44 lines (43 loc) · 1.02 KB
/
3d_surface_area.c
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
#include <assert.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int h,k;
scanf("%d %d",&h,&k);
int sa=2*h*k;
int** a=(int**)calloc(h+2,sizeof(int*));
a[0]=calloc(k+2,sizeof(int));
a[h+1]=calloc(k+2,sizeof(int));
for(int i=1;i<=h;i++){
a[i]=calloc(k+2,sizeof(int));
for(int j=1;j<=k;j++){
int x;
scanf("%d",&x);
a[i][j]+=x;
}
}
for(int i=1;i<=h;i++){
for(int j=1;j<=k;j++){
if(a[i][j]>a[i][j+1]){
sa+=a[i][j]-a[i][j+1];
}
if(a[i][j]>a[i][j-1]){
sa+=a[i][j]-a[i][j-1];
}
if(a[i][j]>a[i+1][j]){
sa+=a[i][j]-a[i+1][j];
}
if(a[i][j]>a[i-1][j]){
sa+=a[i][j]-a[i-1][j];
}
}
}
printf("%d",sa);
}