From 10a473d912bbecd72daf91a6a557beb56804d5e0 Mon Sep 17 00:00:00 2001 From: Aayushi Mittal <60853067+Aayushi-Mittal@users.noreply.github.com> Date: Tue, 6 Oct 2020 15:57:34 +0530 Subject: [PATCH 1/2] Create Question.md --- .../Question.md | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Task 1/2D Array - Alternating rectangles of O and X/Question.md diff --git a/Task 1/2D Array - Alternating rectangles of O and X/Question.md b/Task 1/2D Array - Alternating rectangles of O and X/Question.md new file mode 100644 index 00000000..f9dc567f --- /dev/null +++ b/Task 1/2D Array - Alternating rectangles of O and X/Question.md @@ -0,0 +1,27 @@ +# 2D Array - Alternating rectangles of O and X +Write a code which inputs two numbers m and n and creates a matrix of size m x n (m rows and n columns) in which every elements is either X or 0. The Xs and 0s must be filled alternatively, the matrix should have outermost rectangle of Xs, then a rectangle of 0s, then a rectangle of Xs, and so on.. + +### Input Format +You need to tell that how many rows and columns your matrix need to have and these values should be separated by space. +### Constraints +1 <= n,m <= 1000 +### Output Format +Print the resultant matrix to the stdout. +### [Link of the question](https://www.techgig.com/practice/question/2d-array-alternating-rectangles-of-o-and-x/MXExbVBCMm83Y0ROcG42RXg2V1hhMy83Skwxdjh0ZWZjZEpqOE1uWEs1QzZINW9DR0dPYXpXR1pvVzJ5N3BpSA==/1) +## Sample TestCase 1 +#### input +``` +6 7 +``` +#### output +``` +X X X X X X X +X 0 0 0 0 0 X +X 0 X X X 0 X +X 0 X X X 0 X +X 0 0 0 0 0 X +X X X X X X X +``` +**Time Limit(X)** : 1.00 sec(s) for each input. + +**Memory Limit** : 512 MB From ca5592e008323a61687859665fdc131a17568ad6 Mon Sep 17 00:00:00 2001 From: Aayushi Mittal <60853067+Aayushi-Mittal@users.noreply.github.com> Date: Tue, 6 Oct 2020 16:07:51 +0530 Subject: [PATCH 2/2] Add solution of Task 1 cpp problem --- .../Solution.cpp | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 Task 1/2D Array - Alternating rectangles of O and X/Solution.cpp diff --git a/Task 1/2D Array - Alternating rectangles of O and X/Solution.cpp b/Task 1/2D Array - Alternating rectangles of O and X/Solution.cpp new file mode 100644 index 00000000..00709502 --- /dev/null +++ b/Task 1/2D Array - Alternating rectangles of O and X/Solution.cpp @@ -0,0 +1,78 @@ +#include +using namespace std; +int main() +{ + int m, n; + cin>>m>>n; + if(n>=1 && m <= 1000 && m>=1 && n<=1000) + { + int i, j, k=0, p=0, checkr=0, checkc=0; + char mat[m][n]; + + for (i=1; i<=m; i++) + { + p=0; + checkc=0; + for(j=1; j<=n; j++) + { + if((checkr==0 && j>=k+1 && j<=n-k) || (checkc==0 && i>=p+1 && i