Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
看大部分人贴的代码都略丑,给大家来一个model和design稍微好一点的。#include <iostream> using namespace std; char flag[10][7] = { {'-', '|', '|', ' ', '|', '|', '-'}, {' ', ' ', '|', ' ', ' ', '|', ' '}, {'-', ' ', '|', '-', '|', ' ', '-'}, {'-', ' ', '|', '-', ' ', '|', '-'}, {' ', '|', '|', '-', ' ', '|', ' '}, {'-', '|', ' ', '-', ' ', '|', '-'}, {'-', '|', ' ', '-', '|', '|', '-'}, {'-', ' ', '|', ' ', ' ', '|', ' '}, {'-', '|', '|', '-', '|', '|', '-'}, {'-', '|', '|', '-', ' ', '|', '-'} }; int s; char lcd[23][103]; void gen(int r, int c, int d) { for (int i = 0; i < s; i++) { lcd[r][c + 1 + i] = flag[d][0]; lcd[r + 1 + i][c] = flag[d][1]; lcd[r + 1 + i][c + 1 + s] = flag[d][2]; lcd[r + 1 + s][c + 1 + i] = flag[d][3]; lcd[r + 2 + s + i][c] = flag[d][4]; lcd[r + 2 + s + i][c + 1 + s] = flag[d][5]; lcd[r + 2 + 2 * s][c + 1 + i] = flag[d][6]; } } int main() { string num; cin >> s >> num; while (s) { for (int i = 0; i < 2 * s + 3; i++) for (int j = 0; j < num.size() * (s + 3) - 1; j++) lcd[i][j] = ' '; for (int i = 0; i < num.size(); i++) gen(0, (s + 3) * i, num[i] - '0'); for (int i = 0; i < 2 * s + 3; i++) { for (int j = 0; j < num.size() * (s + 3) - 1; j++) cout << lcd[i][j]; cout << endl; } cout << endl; cin >> s >> num; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator