【HDOJ】1332 LC-Display
水题。
1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 5 #define MAXN 11 6 #define LEFT 1 7 #define RIGHT 2 8 #define BOTH 3 9 10 char lcd[10][MAXN][2*MAXN+3+1][MAXN+2+1]; 11 int rr[MAXN]; 12 int cc[MAXN]; 13 14 void addR(int x, int i, int j) { 15 int k; 16 17 for (k=1; k<cc[i]-1; ++k) 18 lcd[x][i][j][k] = '-'; 19 } 20 21 void addC(int x, int i,int j, int v) { 22 if (v & LEFT) 23 lcd[x][i][j][0] = '|'; 24 if (v & RIGHT) 25 lcd[x][i][j][cc[i]-1] = '|'; 26 } 27 28 void init() { 29 int i, j, k; 30 int n; 31 32 for (i=1; i<=10; ++i) { 33 rr[i] = 2*i+3; 34 cc[i] = i+2; 35 } 36 37 memset(lcd, ' ', sizeof(lcd)); 38 39 for (k=0; k<10; ++k) { 40 for (i=1; i<=10; ++i) { 41 for (j=0; j<rr[i]; ++j) { 42 lcd[k][i][j][cc[i]] = '\0'; 43 } 44 } 45 } 46 47 // 0 48 n = 0; 49 for (i=1; i<=10; ++i) { 50 for (j=0; j<rr[i]; ++j) { 51 if (j==0 || j==rr[i]-1) { 52 addR(n, i, j); 53 } else if (j == i+1) { 54 /*do nothing*/; 55 } else { 56 addC(n, i, j, BOTH); 57 } 58 } 59 } 60 61 // 1 62 n = 1; 63 for (i=1; i<=10; ++i) { 64 for (j=0; j<rr[i]; ++j) { 65 if (j==0 || j==i+1 || j==rr[i]-1) { 66 /*do nothing*/; 67 } else { 68 addC(n, i, j, RIGHT); 69 } 70 } 71 } 72 73 // 2 74 n = 2; 75 for (i=1; i<=10; ++i) { 76 for (j=0; j<rr[i]; ++j) { 77 if (j==0 || j==i+1 || j==rr[i]-1) { 78 addR(n, i, j); 79 } else { 80 if (j < i+1) 81 addC(n, i, j, RIGHT); 82 else 83 addC(n, i, j, LEFT); 84 } 85 } 86 } 87 88 // 3 89 n = 3; 90 for (i=1; i<=10; ++i) { 91 for (j=0; j<rr[i]; ++j) { 92 if (j==0 || j==i+1 || j==rr[i]-1) { 93 addR(n, i, j); 94 } else { 95 addC(n, i, j, RIGHT); 96 } 97 } 98 } 99 100 // 4 101 n = 4; 102 for (i=1; i<=10; ++i) { 103 for (j=0; j<rr[i]; ++j) { 104 if (j==0 || j==rr[i]-1) { 105 /*do nothing*/; 106 } else if (j == i+1) { 107 addR(n, i, j); 108 } else { 109 if (j < i+1) 110 addC(n, i, j, BOTH); 111 else 112 addC(n, i, j, RIGHT); 113 } 114 } 115 } 116 117 // 5 118 n = 5; 119 for (i=1; i<=10; ++i) { 120 for (j=0; j<rr[i]; ++j) { 121 if (j==0 || j==i+1 || j==rr[i]-1) { 122 addR(n, i, j); 123 } else { 124 if (j < i+1) 125 addC(n, i, j, LEFT); 126 else 127 addC(n, i, j, RIGHT); 128 } 129 } 130 } 131 132 // 6 133 n = 6; 134 for (i=1; i<=10; ++i) { 135 for (j=0; j<rr[i]; ++j) { 136 if (j==0 || j==i+1 || j==rr[i]-1) { 137 addR(n, i, j); 138 } else { 139 if (j < i+1) 140 addC(n, i, j, LEFT); 141 else 142 addC(n, i, j, BOTH); 143 } 144 } 145 } 146 147 // 7 148 n = 7; 149 for (i=1; i<=10; ++i) { 150 for (j=0; j<rr[i]; ++j) { 151 if (j==0) { 152 addR(n, i, j); 153 } else if (j==i+1 || j==rr[i]-1) { 154 /*do nothing*/; 155 } else { 156 addC(n, i, j, RIGHT); 157 } 158 } 159 } 160 161 // 8 162 n = 8; 163 for (i=1; i<=10; ++i) { 164 for (j=0; j<rr[i]; ++j) { 165 if (j==0 || j==i+1 || j==rr[i]-1) { 166 addR(n, i, j); 167 } else { 168 addC(n, i, j, BOTH); 169 } 170 } 171 } 172 173 // 9 174 n = 9; 175 for (i=1; i<=10; ++i) { 176 for (j=0; j<rr[i]; ++j) { 177 if (j==0 || j==i+1 || j==rr[i]-1) { 178 addR(n, i, j); 179 } else { 180 if (j < i+1) 181 addC(n, i, j, BOTH); 182 else 183 addC(n, i, j, RIGHT); 184 } 185 } 186 } 187 } 188 189 void output(int n) { 190 int i, j, k; 191 192 for (i=0; i<10; ++i) { 193 for (j=0; j<rr[n]; ++j) { 194 printf("%s\n", lcd[i][n][j]); 195 } 196 printf("\n\n"); 197 } 198 printf("output finish\n"); 199 } 200 201 int main() { 202 int n; 203 int i, j, k; 204 char s[15]; 205 206 #ifndef ONLINE_JUDGE 207 freopen("data.in", "r", stdin); 208 freopen("data.out", "w", stdout); 209 #endif 210 211 init(); 212 //output(1); 213 214 while (scanf("%d %s", &n, s) != EOF) { 215 if (n==0 && s[0]=='0' && s[1]=='\0') 216 break; 217 for (j=0; j<rr[n]; ++j) { 218 for (i=0; s[i]; ++i) { 219 if (i) 220 printf(" %s", lcd[s[i]-'0'][n][j]); 221 else 222 printf("%s", lcd[s[i]-'0'][n][j]); 223 } 224 printf("\n"); 225 } 226 printf("\n"); 227 } 228 229 return 0; 230 }