Posted on 2010-08-17 14:17
Brian 閱讀(455)
評論(0) 編輯 收藏 引用 所屬分類:
POJ
Description
你的一個朋友買了一臺電腦。他以前只用過計算器,因為電腦的顯示器上顯示的數字的樣子和計算器是不一樣,所以當他使用電腦的時候會比較郁悶。為了幫助他,你決定寫一個程序把在電腦上的數字顯示得像計算器上一樣。
Input
輸入包括若干行,每行表示一個要顯示的數。每行有兩個整數s和n (1 <= s <= 10, 0 <= n <= 99999999),這里n是要顯示的數,s是要顯示的數的尺寸。
如果某行輸入包括兩個0,表示輸入結束。這行不需要處理。
Output
顯示的方式是:用s個'-'表示一個水平線段,用s個'|'表示一個垂直線段。這種情況下,每一個數字需要占用s+2列和2s+3行。另外,在兩個數字之間要輸出一個空白的列。在輸出完每一個數之后,輸出一個空白的行。注意:輸出中空白的地方都要用空格來填充。
Sample Input
2 12345
3 67890
0 0
Sample Output
-- -- --
| | | | | |
| | | | | |
-- -- -- --
| | | | |
| | | | |
-- -- --
--- --- --- --- ---
| | | | | | | |
| | | | | | | |
| | | | | | | |
--- --- ---
| | | | | | | |
| | | | | | | |
| | | | | | | |
--- --- --- ---
Hint
數字(digit)指的是0,或者1,或者2……或者9。
數(number)由一個或者多個數字組成。
這題橫跨我一個學期之久,后來無奈還是百度了一下:
#include <iostream>
using namespace std;
char n1[] = "- -- -----";
char n2[] = "| ||| ||";
char n3[] = "||||| |||";
char n4[] = " ----- --";
char n5[] = "| | | | ";
char n6[] = "|| |||||||";
char n7[] = "- -- -- --";
int main()
{
int m;
char n[10];
cin>>m>>n;
while ((n[0]-'0')||m)
{
int len = strlen(n);
for (int i=0;i<len;i++)
{
cout<<" ";
int num = n[i]-'0';
for (int j=0;j<m;j++)
{
cout<<n1[num];
}
cout<<" ";
}
cout<<endl;
int temp = m;
while (temp--)
{
for (int i=0;i<len;i++)
{
int num = n[i]-'0';
cout<<n2[num];
for (int j=0;j<m;j++)
{
cout<<" ";
}
cout<<n3[num];
cout<<" ";
}
cout<<endl;
}
for (int i=0;i<len;i++)
{
cout<<" ";
int num = n[i]-'0';
for (int j=0;j<m;j++)
{
cout<<n4[num];
}
cout<<" ";
}
cout<<endl;
temp = m;
while (temp--)
{
for (int i=0;i<len;i++)
{
int num = n[i]-'0';
cout<<n5[num];
for (int j=0;j<m;j++)
{
cout<<" ";
}
cout<<n6[num];
cout<<" ";
}
cout<<endl;
}
for (int i=0;i<len;i++)
{
cout<<" ";
int num = n[i]-'0';
for (int j=0;j<m;j++)
{
cout<<n7[num];
}
cout<<" ";
}
cout<<endl<<endl;
cin>>m>>n;
}
return 0;
}
我想,第一次做出來這題的人真是了不起!