Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
C++ code to check given flag is stripped or not
Suppose we have a matrix of size n x m. Each cell will hold one value from 0 to 9. There is a flag should be striped: each horizontal row of the flag should contain squares of the same color, and the colors of the adjacent horizontal rows should be different. We have to check given matrix is valid flag or not.
So, if the input is like
| 0 | 0 | 0 |
| 1 | 1 | 1 |
| 3 | 3 | 3 |
Steps
To solve this, we will follow these steps −
n := row count of matrix m := column count of matrix l := 'm' res := 1 for initialize i := 0, when iExample
Let us see the following implementation to get better understanding −
#includeusing namespace std; bool solve(vector > matrix){ int n = matrix.size(); int m = matrix[0].size(); char l = 'm'; bool res = 1; for (int i = 0; i > matrix = { { 0, 0, 0 }, { 1, 1, 1 }, { 3, 3, 3 } }; cout Input
{ { 0, 0, 0 }, { 1, 1, 1 }, { 3, 3, 3 } }Output
1
Advertisements
