코딩스터디

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

애플앤마블 2019. 5. 13. 00:08
반응형
SMALL

buildings by miranda from the Noun Project

본 문제는 swexpertacademy D3 1206번 문제임을 알립니다. 하단 URL 참조

 

각 층을 입력받고 0층이 입력될 때는 계속 진행하고 층이 입력되면 그 층까지 모두 2차원 배열에 1을 넣는다.

 

그 후 각 경우에 count를 세는데 if(arr[i-1][j]==0&&arr[i-2][j]==0&&arr[i+1][j]==0&&arr[i+2][j]==0) 이 조건에 맞으면 count를 올린다.

#include<iostream>
#include<string.h>
using namespace std;
int main(){
	for(int t=1; t<=10; t++){
    	cout<<"#"<<t<<" ";
        int N;
        cin>>N;
        int arr[N][255];
        memset(arr, 0, sizeof(arr));
        for(int i=0; i<N; i++){
        	int floor;
            cin>>floor;
            if(floor==0) continue;
            else {
            	for(int j=0; j<floor; j++){
                	arr[i][j]=1;
                }
            }
        }
        int count=0;
        for(int i=2; i<N-2; i++){
            for(int j=0; j<255; j++){
            	if(arr[i][j]==1){
                	if(arr[i-1][j]==0&&arr[i-2][j]==0&&arr[i+1][j]==0&&arr[i+2][j]==0) count++;
                }
            }
        }
        cout<<count<<endl;
    }
    return 0;
}

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV134DPqAA8CFAYh&categoryId=AV134DPqAA8CFAYh&categoryType=CODE

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

www.swexpertacademy.com

 

반응형
LIST