http://acm.jlu.edu.cn/joj/showproblem.php?pid=1025
老是Presentation Error,无语了!
#include<iostream>
#include<string>
using namespace std;
//Horizonal state:
//0: skip; 1: '-' required
//Vertical state:
//0: skip; 1: single right '|'
//2: single left '|' 3:both lines
const int lcDisplayData[10][5] = {
{1,3,0,3,1},//0 five rows
{0,1,0,1,0},//1
{1,1,1,2,1},//2
{1,1,1,1,1},//3
{0,3,1,1,0},//4
{1,2,1,1,1},//5
{1,2,1,3,1},//6
{1,1,0,1,0},//7
{1,3,1,3,1},//8
{1,3,1,1,1}//9
};
//H represent Horizonal
//V represent Vertical
//D represent Done
char cdStates[] = {
'H','V','H','V','H','D'
};
string horizonal_segment(int type,int sz){
int i = 0;
string segment = "";
segment.push_back(' ');
switch(type){
case 1:
for(i = 0; i < sz; i++)
segment.push_back('-');
break;
case 0:
for(i = 0; i < sz; i++)
segment.push_back(' ');
break;
default:
break;
}
segment.push_back(' ');
segment.push_back(' ');//blank between digit
return segment;
}
string vertical_segment(int type, int sz){
string segment = "";
int i;
switch(type){
case 1:
segment.push_back(' ');
for(i = 0; i < sz; i++)
segment.push_back(' ');
segment.push_back('|');
break;
case 2:
segment.push_back('|');
for(i = 0; i < sz; i++)
segment.push_back(' ');
segment.push_back(' ');
break;
case 3:
segment.push_back('|');
for(i = 0; i < sz; i++)
segment.push_back(' ');
segment.push_back('|');
break;
default:
segment.push_back(' ');
for(i = 0; i < sz; i++)
segment.push_back(' ');
segment.push_back(' ');
break;
}
segment.push_back(' ');//blank between digit
return segment;
}
void display(int size,string num){
int i,j,k;
for(i = 0; i < 6; i++){
string line = "";
switch(cdStates[i]){
case 'H':
for(j = 0; j < num.length(); j++){
line.append( horizonal_segment(lcDisplayData[ num[j]-'0' ][i],size) );
}
cout << line.substr(0,line.length()-1) << endl;//use substr remove last ' '
break;
case 'V':
for(k = 0; k < size; k++){
line = "";
for(j = 0; j < num.length(); j++){
line.append(vertical_segment(lcDisplayData[ num[j]-'0' ][i],size));
}
cout << line.substr(0,line.length()-1) << endl;
}
break;
case 'D':
break;
}
}
}
int main(){
int size;
string num;
int flag = 0;
while(cin >> size >> num){
if(flag)
cout << endl;
else
flag = 1;
display(size,num);
}
}