
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
C++ code to check pattern is center-symmetrical or not
Suppose we have a 3 x 3 matrix with 'X' and '.'. We have to check whether the pattern is centersymmetrical or not. (More on center symmetry − http://en.wikipedia.org/wiki/Central_symmetry)
So, if the input is like
X | X | . |
. | . | . |
. | X | X |
then the output will be True.
Steps
To solve this, we will follow these steps −
if M[0, 0] is same as M[2, 2] and M[0, 1] is same as M[2, 1] and M[0, 2] is same as M[2, 0] and M[1, 0] is same as M[1, 2], then: return true Otherwise return false
Example
Let us see the following implementation to get better understanding −
#include <bits/stdc++.h> using namespace std; bool solve(vector<vector<char>> M){ if (M[0][0] == M[2][2] && M[0][1] == M[2][1] && M[0][2] == M[2][0] && M[1][0] == M[1][2]) return true; else return false; } int main(){ vector<vector<char>> matrix = { { 'X', 'X', '.' }, { '.', '.', '.' }, { '.', 'X', 'X' } }; cout << solve(matrix) << endl; }
Input
{ { 'X', 'X', '.' }, { '.', '.', '.' }, { '.', 'X', 'X' } }
Output
1
- Related Articles
- C++ code to check string is diverse or not
- C++ code to check given flag is stripped or not
- C++ code to check given matrix is good or not
- C++ Program to check joke programming code is generating output or not
- C++ code to check grasshopper can reach target or not
- Python program to check whether the string is Symmetrical or Palindrome
- C++ code to check all bulbs can be turned on or not
- C++ code to check water pouring game has all winner or not
- Check if a string follows anbn pattern or not in C++
- C++ code to check array can be formed from Equal Not-Equal sequence or not
- Program to check whether given words are maintaining given pattern or not in C++
- Program to check regular expression pattern is matching with string or not in Python
- C++ code to find center of inner box
- C# program to check if string is panagram or not
- C Program to check if matrix is singular or not

Advertisements