I try to print the grid with spaces regard to digits(units digit, tens digit,hundreds digit etc. ). It prints as expected when entered just one decimal numbers.(one digit numbers) If it is thought for `mxn` grid for example 4x12 or 4x101. My aim is to separate using spaces regards to units digit, tens digit,hundreds digit etc. I try to explain it on example:
Code:
4 12
Output:
123456789101112
1............
2.....xo.....
3.....ox.....
4............
Expected output:
123456789101112
1......... . . .
2.....xo.. . . .
3.....ox.. . . .
4......... . . .
4 103
Output
123456789101112.....100101102103
1.........................
2.................xo......
3.................ox......
4.........................
Expected output:
123456789101112.....100101102103
1......... . . . . . . . . .
2......... . . . x o . . . .
3......... . . . o x . . . .
4......... . . . . . . . . .
| ||
one space two spaces
I have also a function to calculate how many decimal places there are.
Code:
int decimalPlace(int num)
{
int decPlace = 0;
do
{
decPlace++;
num=num/10;
}
while(num);
return decPlace;
}
Code:
Code:
#include <iostream>
#include <iomanip>
using namespace std;
char const c_symbol = 'x';
char const p_symbol = 'o';
char const what_symbol = '.';
void show(char const table[][10000], int row_size, int col_size)
{
cout << endl << setw(3);
for(int i = 0 ; i < col_size ; ++i)
cout << i + 1;
cout << endl;
for(int i = 0; i < row_size; ++i)
{
cout << setw(2) << i + 1;
for(int j = 0; j < col_size; j++)
cout << table[i][j];
cout << endl;
}
cout << endl;
}
int main()
{
int row_size;
int col_size;
char table[10000][10000];
cin >> row_size >> col_size;
int center = 0;
for(int i = 0; i < row_size; ++i)
for(int j = 0; j < col_size; ++j)
{
table[i][j] = what_symbol;
}
int row = row_size / 2;
int col = col_size / 2;
table[row][col - 1] = p_symbol;
table[row - 1][col] = p_symbol;
table[row][col] = c_symbol;
table[row - 1][col - 1] = c_symbol;
show(table, row_size, col_size);
return 0;
}