https://www.acmicpc.net/problem/20125
20125번: 쿠키의 신체 측정
쿠키런은 데브시스터즈에서 제작한 모바일 러닝 액션 게임이다. 마녀의 오븐에서 탈출한 쿠키들과 함께 모험을 떠나는 게임으로, 점프와 슬라이드 2가지 버튼만으로 손쉽게 플레이할 수 있는
www.acmicpc.net
생각해 보기
- 머리는 항상 최상단에 존재한다.
- 심장은 머리아래에 존재한다.
- 허리는 심장아래로 쭉 이어져 있다.
- 양다리는 허리 한칸 아래에 존재한다.
코드
더보기
#include<iostream>
#include<vector>
using namespace std;
int N;
string tmp;
vector<string> board;
int hy,hx;
int my[4]={0,1,0,-1};
int mx[4]={1,0,-1,0};
void input(){
cin>>N;
for(int i=0;i<N;++i){
cin>>tmp;
board.push_back(tmp);
}
}
void findHead(){
for(int i=0;i<N;++i){
for(int j=0;j<N;++j){
if(board[i][j]=='*'){
hy=i+1;
hx=j;
cout<<hy+1<<" "<<hx+1<<'\n';
return;
}
}
}
}
int findPart(int sy, int sx, int m){
int cnt=0;
while(sy>=0&&sx>=0&&sy<N&&sx<N&&board[sy][sx]=='*'){
++cnt;
sy+=my[m];
sx+=mx[m];
}
cout<<cnt<<" ";
return cnt;
}
void findParts(){
findPart(hy,hx-1,2);
findPart(hy,hx+1,0);
int leng = findPart(hy+1,hx,1);
findPart(hy+leng+1,hx-1,1);
findPart(hy+leng+1,hx+1,1);
}
void solution(){
findHead();
findParts();
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
input();
solution();
return 0;
}

728x90
'알고리즘 > 백준 문제' 카테고리의 다른 글
| 1244 - 스위치 켜고 끄기 (0) | 2023.02.28 |
|---|---|
| 1205 - 등수 구하기 (0) | 2023.02.27 |
| 25757 - 임스와 함께하는 미니게임 (0) | 2023.02.24 |
| 8979 - 올림픽 (0) | 2023.02.24 |
| 9655 - 돌 게임 (0) | 2023.02.23 |
댓글