题目链接:http://acm.pku.edu.cn/JudgeOnline/problem?id=1102
这里主要用到点阵数组对字符进行编码的技巧,
model存储了参数为s的每个数字的字模,求出来后对字符串进行编码,然后根据点阵输出内容。
#include <iostream>
#include <string>
using namespace std;
#define S 10
#define D 8
void Make(bool model[10][2*S+3][S+2],int s)
{
int i,j,k;
for(i = 0;i < 10;++i)
{
for(j = 0;j < s*2 + 3;++j)
{
for(k = 0;k < s + 2;++k)
model[i][j][k] = false;
}
}
for(i = 0;i < 10;++i)
{
if(i != 1 && i != 4)
{
for(j = 1;j <= s;++j)
model[i][0][j] = true;
}
if(i != 0 && i != 1 && i != 7)
{
for(j = 1;j <= s;++j)
model[i][s+1][j] = true;
}
if(i != 1 && i != 4 && i != 7)
{
for(j = 1;j <= s;++j)
model[i][s*2+2][j] = true;
}
if(i == 0 || i == 4 || i == 8 || i == 9)
{
for(j = 1;j <= s;++j)
model[i][j][0] = model[i][j][s+1] = true;
}
if(i == 5 || i == 6)
{
for(j = 1;j <= s;++j)
model[i][j][0] = true;
}
if(i == 1 || i == 2 || i == 3 || i == 7)
{
for(j = 1;j <= s;++j)
model[i][j][s+1] = true;
}
if(i == 0 || i == 6 || i == 8)
{
for(j = s+2;j < 2*s + 2;++j)
model[i][j][0] = model[i][j][s+1] = true;
}
if(i == 2)
{
for(j = s+2;j < 2*s + 2;++j)
model[i][j][0] = true;
}
if(i == 1 || i == 3 || i == 4 || i == 5 || i == 7 || i == 9)
{
for(j = s+2;j < 2*s + 2;++j)
model[i][j][s+1] = true;
}
}
}
int main()
{
freopen("in.txt","r",stdin);
bool model[10][2*S+3][S+2],code[D][2*S+3][S+2];
int i,j,k,len,size;
string str;
while(cin >> size >> str)
{
if(size == 0 && str == "0")
break;
Make(model,size);
len = str.size();
for(i = 0;i < len;++i)
{
for(j = 0;j < size*2 + 3;++j)
{
for(k = 0;k < size + 2;++k)
code[i][j][k] = model[str[i]-'0'][j][k];
}
}
for(i = 0;i < size*2 + 3;++i)
{
for(j = 0;j < len;++j)
{
for(k = 0;k < size + 2;++k)
{
if(code[j][i][k])
{
if(i == 0 || i == size + 1 || i == size*2 + 2)
cout << '-';
else
cout << '|';
}
else
cout << ' ';
}
cout << ' ';
}
cout << endl;
}
cout << endl;
}
return 0;
}