크레인 인형뽑기

computer_log·2023년 8월 29일
0
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<vector<int>>board = { {0,0,0,0,0},{0,0,1,0,3},{0,2,5,0,1},{4,2,4,4,2},{3,5,1,3,1} };
vector<int>moves = { 1,5,3,5,1,2,1,4 };

vector<vector<int>>map(5);
vector<int>result;
int cnt = 0;
void push(int dall) {
	if (result.size() == 0) {
		result.push_back(dall);
	}
	else {
		int old = result[result.size() - 1];
		if (old == dall) {
			result.pop_back();
			cnt += 2;
		}
		else {
			result.push_back(dall);
		}
	}
}
void mapMoves(int change) {
	if (map[change].size() == 0)return;
	int dall = map[change][map[change].size() - 1];
	map[change].pop_back();
	push(dall);

}
void input() {
	for (int x = 0; x < 5; x++) {
		for (int y = 4; y >= 0; y--) {
			int tar = board[y][x];
			if (tar == 0)continue;
			map[x].push_back(tar);
		}
	}
}

int main() {

	input();
	for (int i = 0; i < moves.size(); i++) {
		int change = moves[i] - 1;
		mapMoves(change);
	}
	cout << cnt << "\n";

	return 0;
}

[출력]

4

배운점

1)continue

continue는 반복문에서만 빠져나갈수있는고

함수에서 빠져나갈려묜 returnn 쓰기!

profile
computer_log

0개의 댓글