简单模拟题,设计一个好的数据结构来方便的表达每个数字的输出方式。 我的不是最好的,后来还看到 Kaipeng Liu 的方法,写起来更利索一些;) 返回 Volume VII 索引 返回总索引 下面是我的代码 ////////////////////////////////////////////////////////////////////////// // 706 - LCD-Display // Copyright (c) 2010 by Bo-wen Feng // balonfan@gmail.com ////////////////////////////////////////////////////////////////////////// #include <set> #include <map> #include <list> #include <queue> #include <stack> #include <vector> #include <string> #include <sstream> #include <cstdio> #include <cmath> #include <limits> #include <utility> #ifndef ONLINE_JUDGE #include <fstream> std::ifstream cin("in.txt"); std::ofstream cout("out.txt"); // std::ofstream cout(stdout); #else #include <iostream> #endif typedef long long llong; typedef unsigned long long ullong; typedef long double ldouble; using namespace std; #define MAX_DIGIT 20 // 0 1 2 3 4 5 6 7 8 9 char part1[10] = { '-', ' ', '-', '-', ' ', '-', '-', '-', '-', '-' }; char part2[20] = { '|','|', ' ','|', ' ','|', ' ','|', '|','|', '|',' ', '|',' ', ' ','|', '|','|', '|','|' }; char part3[10] = { ' ', ' ', '-', '-', '-', '-', '-', ' ', '-', '-' }; char part4[20] = { '|','|', ' ','|', '|',' ', ' ','|', ' ','|', ' ','|', '|','|', ' ','|', '|','|', ' ','|' }; char part5[10] = { '-', ' ', '-', '-', ' ', '-', '-', ' ', '-', '-' }; void PrintPart135(char part[], int s, char* num, int nDigit) { char ch; int d; for(int i = 0; i < nDigit; ++i) { if(i > 0) cout<< ' '; d = num[i] - '0'; cout<< ' '; ch = part[d]; for(int j = 0; j < s; ++j) { cout<< ch; } cout<< ' '; } cout<< '/n'; } void PrintPart24(char part[], int s, char* num, int nDigit) { int d; for(int k = 0; k < s; ++k) { for(int i = 0; i < nDigit; ++i) { if(i > 0) cout<< ' '; d = ((num[i] - '0') << 1); char ch1 = part[d]; char ch2 = part[d + 1]; cout<< ch1; for(int j = 0; j < s; ++j) cout<< ' '; cout<< ch2; } cout<< '/n'; } } int main(int argc, char* argv[]) { int s; char num[MAX_DIGIT]; int nDigit; cin>> s>> num; while(s > 0) { nDigit = strlen(num); PrintPart135(part1, s, num, nDigit); PrintPart24 (part2, s, num, nDigit); PrintPart135(part3, s, num, nDigit); PrintPart24 (part4, s, num, nDigit); PrintPart135(part5, s, num, nDigit); cout<< '/n'; cin>> s>> num; } return 0; }