Home>Article>Backend Development> 【C++ Fun Program】Happy Xiaoxiaole

【C++ Fun Program】Happy Xiaoxiaole

little bottle
little bottle forward
2019-04-09 15:44:39 3797browse

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.

Analysis

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 judge
Whether the two exchanged gridsare eliminated.

The key point is:

  1. You only need to swap right and downward, because when traversing, subsequent swaps will be repeated. The former one determines whether the right exchange is eliminated, and the latter traversal does not need to determine whether the left exchange is repeated.
  2. It is necessary to judge whether the two exchanged grids can be eliminated in order to achieve a comprehensive judgment.

Code

// // 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!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete