I have solved this problem from SPOJ and the code runs well. I want to improve this code using C++11 or C++14.
Using two characters: . (dot) and * (asterisk) print a grid-like pattern. The grid will have l lines, c columns, and each square shaped element of the grid will have the height and width equal to s.
Moreover, each of the grid elements will have a diagonal. The diagonal of the first square in the first line of the grid is directed towards down and right corner - use the \ (backslash) character to print it; while the next diagonal will be directed towards upper right corner - use the / (slash) character to print it. Print the successive diagonals alternately (please consult the example below).
Input
You are given t - the number of test cases and for each of the test case three positive integers: l - the number of lines, c - the number of columns in the grid and s - the size of the single square shaped element.
Output
For each of the test cases output the requested pattern (please have a look at the example). Use one line break in between successive patterns.
Example
Input:
3
3 1 2
4 4 1
2 5 2
Output:
****
*\.*
*.\*
****
*./*
*/.*
****
*\.*
*.\*
****
*********
*\*/*\*/*
*********
*/*\*/*\*
*********
*\*/*\*/*
*********
*/*\*/*\*
*********
****************
*\.*./*\.*./*\.*
*.\*/.*.\*/.*.\*
****************
*./*\.*./*\.*./*
*/.*.\*/.*.\*/.*
****************
Time Limit 1s
Source Limit 50000 B
Memory Limit 1536 MB
Here is the code
#include <iostream>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int l, c, s;
cin >> l >> c >> s;
int breadth = (c * (s + 1)) + 1;
int height = (l * (s + 1)) + 1;
for(int i = 0; i < height; i++)
{
for(int j = 0; j < breadth; j++)
{
if(i % (s+1) == 0 || j % (s+1) == 0)
{
cout << "*";
}
else if((i/(s+1) + j/(s+1)) % 2 == 0)
{
if(i % (s+1) == j % (s+1))
{
cout << "\\";
}
else
{
cout << ".";
}
}
else
{
if(i % (s+1) == (s+1) - (j % (s+1)))
{
cout <<"/";
}
else
{
cout << ".";
}
}
}
cout << "\n";
}
cout << "\n";
}
}