Home>Article>Backend Development> 【C++ Fun Program】Happy Xiaoxiaole
Are you like the editor, you always like to pick up your mobile phone and open mini games to play in your spare time. This article is about the production process of the C version of the popular game Happy Xiaoxiaole. Friends who are interested can learn about it!
Problem Description
Given a matrix, determine which grid to move to achieve elimination. (define three in a row to eliminate)
It is said to be Huawei's written test question.
First write a function to determine whether the grid containing (i, j) can be eliminated.
Thenswap right and down
, and then call the function written above to judgeWhether the two exchanged grids
are eliminated.
The key point is:
// // main.cpp // huawei // // Created by SteveWong on 11/10/2016. // Copyright © 2016 SteveWong. All rights reserved. // #include#include #include #include //#include using namespace std; const int LEN = 8; void pmap(int map[][LEN]) { for (int i = 0; i < LEN; ++i) { for (int j = 0; j < LEN; ++j) { cout << map[i][j] << " "; } cout << endl; } } // 检查以(i,j)为中心的点, 看是否可以消除 bool check(int map[][LEN], int i, int j)// 保证i、j不越界, { if ( (i-1>=0 && i+1 =0 && j+1 =0 && map[i-2][j]==map[i-1][j]&&map[i-1][j]==map[i][j]) || (j-2>=0 && map[i][j-2]==map[i][j-1]&&map[i][j-1]==map[i][j]) || (i+2 [Recommended course:C Video Tutorial]
The above is the detailed content of 【C++ Fun Program】Happy Xiaoxiaole. For more information, please follow other related articles on the PHP Chinese website!