~cpp // no706 - LCD Display #include <iostream> #include <cstdlib> #include <cstring> using namespace std; const int MAX_LINE = 2000; // test case의 수 const int MAX_ROW = 23; const int MAX_COL = 103; struct Digit // 숫자 { int size; // 크기 char num[9]; // 수 }; int inAnaloge(Digit * d); void makeDisplay(Digit * d, const int line); void showDisplay(char pd[][MAX_COL], int row, int index); void toDigital(char pd[][MAX_COL], int row, int col, int index, char c); int main() { Digit digits[MAX_LINE]; // 입력받을 Analoge 숫자 int line = inAnaloge(digits); // 처리해야 될 줄 수 makeDisplay(digits, line); return 0; } int inAnaloge(Digit * d) { int count = 0; int size; char str[9]; while(cin >> size >> str) { int n = atoi(str); if (size == 0) break; strcpy(d[count].num, str); d[count].size = size; count++; } return count; } void makeDisplay(Digit * d, const int line) { char display[MAX_ROW][MAX_COL]; // display에 담길 Digital 숫자 int i, j, k; int row, col; int index; for (i=0; i<line; i++) { row = 2 * d[i].size + 3; col = d[i].size + 2; for (j=0; j<MAX_ROW; j++) // 공백으로 초기화 { for (k=0; k<MAX_COL; k++) display[j][k] = ' '; } for (j=0; j<9; j++) { if (d[i].num[j] != '') toDigital(display, row, col, j, d[i].num[j]); else break; } index = col * j + (j - 1); showDisplay(display, row, index); cout << endl; } } void showDisplay(char pd[][MAX_COL], int row, int index) { int i, j; for (i=0; i<row; i++) { for (j=0; j<index; j++) cout << pd[i][j]; cout << endl; } } void toDigital(char pd[][MAX_COL], int row, int col, int index, char c) { int i; int s = col - 2; int start = index * col + index; int end = start + col - 1; bool m1 = false, m2 = false, m3 = false; bool l1 = false, l2 = false, l3 = false; bool r1 = false, r2 = false, r3 = false; switch(c) { case '0': l1 = l2 = m1 = m3 = r1 = r2 = true; break; case '1': r1 = r2 = true; break; case '2': m1 = r1 = m2 = l2 = m3 = true; break; case '3': m1 = r1 = m2 = r2 = m3 = true; break; case '4': l1 = m2 = r1 = r2 = true; break; case '5': m1 = l1 = m2 = r2 = m3 = true; break; case '6': m1 = l1 = m2 = l2 = m3 = r2 = true; break; case '7': m1 = r1 = r2 = true; break; case '8': l1 = l2 = r1 = r2 = m1 = m2 = m3 = true; break; case '9': m1 = l1 = m2 = r1 = r2 = m3 = true; break; } if (m1 || m2 || m3) { for (i = start+1; i < end; i++) { if (m1) pd[0][i] = '-'; if (m2) pd[s+1][i] = '-'; if (m3) pd[2*s+2][i] = '-'; } } if (l1 || r1) { for (i = 1; i < s + 1; i++) { if (l1) pd[i][start] = '|'; if (r1) pd[i][start+s+1] = '|'; } } if (l2 || r2) { for (i = s + 2; i < 2 * s + 2; i++) { if (l2) pd[i][start] = '|'; if (r2) pd[i][start+s+1] = '|'; } } }