Skip to content

Instantly share code, notes, and snippets.

@edg-l
Created December 23, 2018 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edg-l/185f4405ac5930db0dcd9b76bf001dc9 to your computer and use it in GitHub Desktop.
Save edg-l/185f4405ac5930db0dcd9b76bf001dc9 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int number_of_digits(int n) {
if(n < 10)
return 1;
return 1 + number_of_digits(n / 10);
}
int max_size(int n, int r) {
// digits * rows, slashes, dot
return number_of_digits(n) * (r * 2) + (r * 2 - 2) + 1;
}
int main() {
int n, r;
cin >> n >> r;
int digits = number_of_digits(n);
int size = max_size(n, r);
for(int i = 1; i <= r; i++) {
int num_print = i * 2;
int half_print = num_print / 2;
int slashes = num_print - 2;
int dot_count = size - slashes - (num_print * digits);
for(int j = 0; j < half_print; j++) {
cout << n;
if(slashes > 0 && (half_print - j - 1) != 0) {
cout << "-";
--slashes;
}
}
for(int j = 0; j < dot_count; j++) {
cout << ".";
}
for(int j = 0; j < half_print; j++) {
cout << n;
if(slashes > 0 && (half_print - j - 1) != 0) {
cout << "-";
--slashes;
}
}
cout << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment