UVa 706 Problem: LC-Display (PC 110104)
2014-01-10 22:01
1791 查看
/* A friend of yours has just bought a new computer. Before this, the most powerful machine he ever used was a pocket calculator. He is a little disappointed because he liked the LCD display of his calculator more than the screen on his new computer! To make him happy, write a program that prints numbers in LCD display style. Input The input file contains several lines, one for each number to be displayed. Each line contains integers s and n, where n is the number to be displayed ( 0n99, 999, 999) and s is the size in which it shall be displayed ( 1s10). The input will be terminated by a line containing two zeros, which should not be processed. Output Print the numbers specified in the input file in an LCD display-style using s ``-'' signs for the horizontal segments and s ``|'' signs for the vertical ones. Each digit occupies exactly s + 2 columns and 2s + 3 rows. Be sure to fill all the white space occupied by the digits with blanks, including the last digit. There must be exactly one column of blanks between two digits. Output a blank line after each number. You will find an example of each digit in the sample output below. Sample Input 2 12345 3 67890 0 0 Sample Output -- -- -- | | | | | | | | | | | | -- -- -- -- | | | | | | | | | | -- -- -- --- --- --- --- --- | | | | | | | | | | | | | | | | | | | | | | | | --- --- --- | | | | | | | | | | | | | | | | | | | | | | | | --- --- --- --- */ //方法貌似搓了点,但是速度还可以 #include <iostream> #include <string> #include <string.h> #include <map> #include <stdio.h> #include <algorithm> #include <queue> #include <vector> #include <math.h> #include <set> #define Max(a,b) ((a)>(b)?(a):(b)) #define Min(a,b) ((a)<(b)?(a):(b)) #define Max_S 12 using namespace std; int S; string NumStr; char Matrix[2*Max_S + 3][(Max_S + 3)*8];//存放LCD显示数字,初始化全部为空格 //从上向下,从左向右,分成7笔画,分别为f1至f7 void f1(int k) { for(int i = 2;i <= S + 1;i++) { Matrix[1][i + (S + 3)*k] = '-'; } } void f2(int k) { for(int i = 2;i <= S + 1;i++) { Matrix[i][1 + (S + 3)*k] = '|'; } } void f3(int k) { for(int i = 2;i <= S + 1;i++) { Matrix[i][S + 2 + (S + 3)*k] = '|'; } } void f4(int k) { for(int i = 2;i <= S + 1;i++) { Matrix[S + 2][i + (S + 3)*k] = '-'; } } void f5(int k) { for(int i = S + 3;i <= 2*S + 2;i++) { Matrix[i][1 + (S + 3)*k] = '|'; } } void f6(int k) { for(int i = S + 3;i <= 2*S + 2;i++) { Matrix[i][S + 2 + (S + 3)*k] = '|'; } } void f7(int k) { for(int i = 2;i <= S + 1;i++) { Matrix[2*S + 3][i + (S + 3)*k] = '-'; } } //初始化Maxtrix void init() { for(int i = 1;i <= 2*S + 3;i++) { for(int j = 1;j <= (S + 3)*8 - 1;j++) { Matrix[i][j] = ' '; } } } //将数字字符转换成LCD显示,每个数字由对应笔画组成 void Change(char ch,int k) { switch(ch) { case '0':{f1(k);f2(k);f3(k);f5(k);f6(k);f7(k);break;} case '1':{f3(k);f6(k);break;} case '2':{f1(k);f3(k);f4(k);f5(k);f7(k);break;} case '3':{f1(k);f3(k);f4(k);f6(k);f7(k);break;} case '4':{f2(k);f3(k);f4(k);f6(k);break;} case '5':{f1(k);f2(k);f4(k);f6(k);f7(k);break;} case '6':{f1(k);f2(k);f4(k);f5(k);f6(k);f7(k);break;} case '7':{f1(k);f3(k);f6(k);break;} case '8':{f1(k);f2(k);f3(k);f4(k);f5(k);f6(k);f7(k);break;} case '9':{f1(k);f2(k);f3(k);f4(k);f6(k);f7(k);break;} } } //显示整个数字 void Print() { for(int i = 1;i <= 2*S + 3;i++) { for(int j = 1;j <= (S + 3)*NumStr.length() - 1;j++) { printf("%c",Matrix[i][j]); } printf("\n"); } } int main() { while(cin>>S>>NumStr,S != 0) { init(); for(int i = 0;i < NumStr.length();i++) { Change(NumStr[i],i); } Print(); printf("\n"); } return 0; }
相关文章推荐
- UVa Problem 706 LC-Display (液晶显示屏)
- UVa Problem Solution: 706 - LC-Display
- UVa Problem 706 LC-Display (液晶显示屏)
- uva 706 LC-Display
- PC110104(液晶显示屏)(LC-Display)
- LC-Display(UVa706)
- UVA 706 - LC-Display
- UVa 706 LC-Display
- uva706 LC-Display
- UVALive5642 UVA706 HDU1332 POJ1102 LC-Display【打印图案】
- UVA 706 LC-Display
- PC/UVa 题号: 110104/706 LC-Display (液晶显示屏)题解
- UVa——110104 LC-Display(图形输出)
- PC 110104 LC-Display 液晶显示屏//字符串 水题
- 模拟 UVa 706 LC-Display
- uva 706 LC-Display
- UVa 706 & ZOJ 1146 LC-Display
- uva 706 LCD Display
- UVA 706 - LCD Display(液晶显示器)
- uva_706_LCD-Display