[UVA] 706 - LC-Display
題目連結
/* 題目: UVa 706 - LC-Display
* Language: C++
* Created on: 2020年2月1日
* Author: hanting
*/
#include <iostream>
#include <vector>
using namespace std;
#define Char2Num(x) (x-'0')
int LCD[10][7] = { // 7 position can display dash '-'
{1, 0, 1, 1, 1, 1, 1},
{0, 0, 0, 0, 0, 1, 1},
{1, 1, 1, 0, 1, 1, 0},
{1, 1, 1, 0, 0, 1, 1},
{0, 1, 0, 1, 0, 1, 1},
{1, 1, 1, 1, 0, 0, 1},
{1, 1, 1, 1, 1, 0, 1},
{1, 0, 0, 0, 0, 1, 1},
{1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 0, 1, 1}
};
void drawDisplay(vector<string> &display, int j, char symbol)
{
int up = 0;
int middle = display.size()/2;
int down = display.size()-1;
if(j == 0)
{
for(int i = 1; i < display[up].size()-1; i++)
display[up][i] = symbol;
}
else if(j == 1)
{
for(int i = 1; i < display[middle].size()-1; i++)
display[middle][i] = symbol;
}
else if(j == 2)
{
for(int i = 1; i < display[down].size()-1; i++)
display[down][i] = symbol;
}
else if(j == 3)
{
for(int i = 1; i < middle; i++)
display[i][0] = symbol;
}
else if(j == 4)
{
for(int i = middle+1; i < down; i++)
display[i][0] = symbol;
}
else if(j == 5)
{
for(int i = 1; i < middle; i++)
display[i][display[i].size()-1] = symbol;
}
else if(j == 6)
{
for(int i = middle+1; i < down; i++)
display[i][display[i].size()-1] = symbol;
}
}
string operator * (string &str, int mul)
{
string result = "";
while(mul--)
{
result += str;
}
return result;
}
main()
{
int s;
string n;
while(cin >> s >> n && s)
{
vector<string> output(3+s*2);
for(int i = 0; i < n.size(); i++)
{
int num = Char2Num(n[i]);
string space = " ";
vector<string> display(3+s*2, space*(s+2));
for(int j = 0; j < 3; j++)
{
if(LCD[num][j])
{
drawDisplay(display, j, '-');
}
}
for(int j = 3; j < 7; j++)
{
if(LCD[num][j])
{
drawDisplay(display, j, '|');
}
}
for(int j = 0; j < 3+s*2; j++)
{
output[j] += display[j];
if(i != n.size()-1)
output[j] += " ";
}
}
for(int i = 0; i < output.size(); i++)
{
cout << output[i] << endl;
}
cout << endl;
}
}
沒有留言:
張貼留言