I received WA for the program included below. Can anyone please tell me an input on which it fails, and what the expected output should be for that input?
Code: Select all
/* @JUDGE_ID: 29339ZA 706 C++ "Getting Started" */
#include<iostream.h>
#include <string>
#include <cmath>
using namespace std;
void display(int s, int n);
void displayHoriz(int row, int s, int digits[], int digitsLen);
void displayVert(int row, int s, int digits[], int digitsLen);
void main()
{
int s, n;
while (cin >> s >> n) {
if (s == 0 && n == 0) {
break;
}
display(s, n);
}
}
const char DIGITS[10][5][3] = {{{' ', '-', ' '}, // 0
{'|', ' ', '|'},
{' ', ' ', ' '},
{'|', ' ', '|'},
{' ', '-', ' '}},
{{' ', ' ', ' '}, // 1
{' ', ' ', '|'},
{' ', ' ', ' '},
{' ', ' ', '|'},
{' ', ' ', ' '}},
{{' ', '-', ' '}, // 2
{' ', ' ', '|'},
{' ', '-', ' '},
{'|', ' ', ' '},
{' ', '-', ' '}},
{{' ', '-', ' '}, // 3
{' ', ' ', '|'},
{' ', '-', ' '},
{' ', ' ', '|'},
{' ', '-', ' '}},
{{' ', ' ', ' '}, // 4
{'|', ' ', '|'},
{' ', '-', ' '},
{' ', ' ', '|'},
{' ', ' ', ' '}},
{{' ', '-', ' '}, // 5
{'|', ' ', ' '},
{' ', '-', ' '},
{' ', ' ', '|'},
{' ', '-', ' '}},
{{' ', '-', ' '}, // 6
{'|', ' ', ' '},
{' ', '-', ' '},
{'|', ' ', '|'},
{' ', '-', ' '}},
{{' ', '-', ' '}, // 7
{' ', ' ', '|'},
{' ', ' ', ' '},
{' ', ' ', '|'},
{' ', ' ', ' '}},
{{' ', '-', ' '}, // 8
{'|', ' ', '|'},
{' ', '-', ' '},
{'|', ' ', '|'},
{' ', '-', ' '}},
{{' ', '-', ' '}, // 9
{'|', ' ', '|'},
{' ', '-', ' '},
{' ', ' ', '|'},
{' ', '-', ' '}}};
void display(int s, int n) {
int digitsLen = int(log10(n)) + 1;
int* digits = new int[digitsLen];
int nn = n;
int i;
for (i = digitsLen - 1; i >= 0; i--) {
digits[i] = nn % 10;
nn /= 10;
}
for (i = 0; i < 5; i++) {
if (i % 2 == 0) {
displayHoriz(i, s, digits, digitsLen);
}
else {
displayVert(i, s, digits, digitsLen);
}
}
cout << endl;
}
void displayHoriz(int row, int s, int digits[], int digitsLen) {
for (int i = 0; i < digitsLen; i++) {
int digit = digits[i];
cout << ' ';
for (int j = 0; j < s; j++) {
cout << DIGITS[digit][row][1];
}
cout << ' ';
if (i < digitsLen - 1) {
cout << ' ';
}
}
cout << endl;
}
void displayVert(int row, int s, int digits[], int digitsLen) {
for (int k = 0; k < s; k++) {
for (int i = 0; i < digitsLen; i++) {
int digit = digits[i];
cout << DIGITS[digit][row][0];
for (int j = 0; j < s; j++) {
cout << ' ';
}
cout << DIGITS[digit][row][2];
if (i < digitsLen - 1) {
cout << ' ';
}
}
cout << endl;
}
}