poj 1102 LC-Display(模拟)
生活随笔
收集整理的這篇文章主要介紹了
poj 1102 LC-Display(模拟)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目:http://poj.org/problem?id=1102
LC-Display| Time Limit:?1000MS | ? | Memory Limit:?10000K |
| Total Submissions:?15752 | ? | Accepted:?6291 |
Description
A friend of you has just bought a new computer. Until now, the most powerful computer he ever used has been a pocket calculator. Now, looking at his new computer, he is a bit disappointed, because he liked the LC-display of his calculator so much. So you decide to write a program that displays numbers in an LC-display-like style on his computer.Input
The input contains several lines, one for each number to be displayed. Each line contains two integers s, n (1 <= s <= 10, 0 <= n <= 99 999 999), where n is the number to be displayed and s is the size in which it shall be displayed.?The input file will be terminated by a line containing two zeros. This line should not be processed.
Output
Output the numbers given in the input file in an LC-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, also for the last digit.) There has to be exactly one column of blanks between two digits.?Output a blank line after each number. (You will find a sample of each digit in the sample output.)
Sample Input
2 12345 3 67890 0 0Sample Output
-- -- -- | | | | | | | | | | | | -- -- -- -- | | | | || | | | |-- -- -- --- --- --- --- --- | | | | | | | | | | | | | | | | | | | | | | | |--- --- --- | | | | | | | | | | | | | | | | | | | | | | | |--- --- --- --- 分析:是的,這就是一道模擬題,僅此而已。需要細心。我是先把8按照尺寸要求寫出來,然后其他數字再在8的基礎上抹去某些筆畫,再保存該數字。解題時我干了一件用時間換空間的傻事,n<1e9的,頂多8位數,我神乎其神的誤認為保存結果的話需要1e9的數組空間,||-_- 是一維為9的空間!下面的代碼數組直接二維,沒有保存所有的數字信息,寫出一個數字print一部分,這時間浪費的啊。。還好過了。。
#include <iostream> #include <cstdio> #include <cstring> using namespace std; int s; char n[20],eight[35][20],str[35][20]; void printblank(){for(int i=0;i<2*s+3;i++) printf(" \n"); } void createight(){memset(eight,0,sizeof(eight));eight[0][0]=' '; for(int j=1;j<s+1;j++) eight[0][j]='-'; eight[0][s+1]=' ';for(int i=1;i<s+1;i++){eight[i][0]='|'; for(int j=1;j<s+1;j++) eight[i][j]=' '; eight[i][s+1]='|';}eight[s+1][0]=' '; for(int j=1;j<s+1;j++) eight[s+1][j]='-'; eight[s+1][s+1]=' ';for(int i=s+2;i<2*s+2;i++){eight[i][0]='|'; for(int j=1;j<s+1;j++) eight[i][j]=' '; eight[i][s+1]='|';}eight[2*s+2][0]=' '; for(int j=1;j<s+1;j++) eight[2*s+2][j]='-'; eight[2*s+2][s+1]=' '; } void clear(int p){if(p==1) for(int j=0;j<s+2;j++) str[0][j]=' ';else if(p==2) for(int i=1;i<s+1;i++) str[i][0]=' ';else if(p==3) for(int i=1;i<s+1;i++) str[i][s+1]=' ';else if(p==4) for(int j=0;j<s+2;j++) str[s+1][j]=' ';else if(p==5) for(int i=s+2;i<2*s+2;i++) str[i][0]=' ';else if(p==6) for(int i=s+2;i<2*s+2;i++) str[i][s+1]=' ';else if(p==7) for(int j=0;j<s+2;j++) str[2*s+2][j]=' '; } void copy(){for(int i=0;i<2*s+3;i++){for(int j=0;j<s+2;j++) str[i][j]=eight[i][j];} } void print(int x){copy();if(x==1){ clear(1); clear(2); clear(4); clear(5); clear(7); }else if(x==2){ clear(2); clear(6); }else if(x==3){ clear(2); clear(5); }else if(x==4){ clear(1); clear(5); clear(7); }else if(x==5){ clear(3); clear(5); }else if(x==6){ clear(3); }else if(x==7){ clear(2); clear(4); clear(5); clear(7); }else if(x==9){ clear(5); }else if(x==0){ clear(4); } } int main() {//freopen("cin.txt","r",stdin);while(cin>>s>>n){if(s==0&&n[0]=='0') break;createight();int length=strlen(n);int i,j,k;for(i=0;i<2*s+3;i++){for(k=0;k<length;k++){print(n[k]-'0');for(j=0;j<s+2;j++) printf("%c",str[i][j]);printf(" ");}puts("");}puts("");}return 0; }
總結
以上是生活随笔為你收集整理的poj 1102 LC-Display(模拟)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: unity 实现简易打飞碟游戏
- 下一篇: 2022年我国城镇污水处理运营市场空间可