시나브로

[D3] 1206. [S/W 문제해결 기본] 1일차 - View 본문

알고리즘/SW Expert Academy

[D3] 1206. [S/W 문제해결 기본] 1일차 - View

혬혬 2019. 10. 6. 10:49
728x90

 

#include<stdio.h>
#include<stdlib.h>
int main(void) {
	int land[1001] = { 0 };
	int problemnumber = 0, i = 0, q = 0;
	for (i = 0; i < 10; i++) {
		scanf( "%d", &problemnumber);
		for (q = 0; q < problemnumber; q++) {
			scanf( "%d ", &land[q]);
		}
		int good_building = 0;
		for (q = 0; q < problemnumber; q++) {
			if ((land[q] > land[q - 1] && land[q] > land[q - 2]) && (land[q] > land[q + 1] && land[q] > land[q + 2])) {
				int max = 0,family=0;
				if (max < land[q - 1])
					max = land[q - 1];
				if (max < land[q - 2])
					max = land[q - 2];
				if (max < land[q + 1])
					max = land[q + 1];
				if (max < land[q +2])
					max = land[q +2];
				family = land[q] - max;
				good_building+=family;
			}
		}
		printf( "#%d %d\n",i+1, good_building);
	}
	return 0;
}
728x90
Comments