天天看点

poj1102解题报告

题目大意:给定字体大小,和一个数,将这个数按给定的字体大小显示出来。。。。

Sample Input

2 12345
3 67890
0 0      

Sample Output

--   --        -- 
   |    |    | |  | | 
   |    |    | |  | | 
      --   --   --   -- 
   | |       |    |    |
   | |       |    |    |
      --   --        -- 

 ---   ---   ---   ---   --- 
|         | |   | |   | |   |
|         | |   | |   | |   |
|         | |   | |   | |   |
 ---         ---   --- 
|   |     | |   |     | |   |
|   |     | |   |     | |   |
|   |     | |   |     | |   |
 ---         ---   ---   ---      
思路:有点像数字逻辑学的7段数字管,把0~9每个数字的对应7段数字管打表,然后对应位置判断是否应该输出即可      
#include<iostream>
using namespace std;
int te[10][7]={1,1,1,1,1,1,0,0,1,1,0,0,0,0,1,1,0,1,1,0,1,1,1,1,1,0,0,1,0,1,1,0,0,1,1,1,0,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,1,1};
int main()
{
	int size,i,j,s;		char str[20];
	while(cin>>size&&size)
	{
		cin>>str;
		for(i=0;i<strlen(str);i++)
		{
			cout<<" ";
			for(j=1;j<=size;j++)
				if(te[str[i]-48][0]==1)	cout<<"-";
				else
					cout<<" ";
			for(j=1;j<=2;j++)
				cout<<" ";
		}
		cout<<endl;

		for(i=1;i<=size;i++)
		{
			for(j=0;j<strlen(str);j++)
			{
				if(te[str[j]-48][5]==1)
					cout<<"|";
				else
					cout<<" ";
				for(s=1;s<=size;s++)
					cout<<" ";
				if(te[str[j]-48][1]==1)
					cout<<"|";
				else
					cout<<" ";
				for(s=1;s<=1;s++)
					cout<<" ";
			}
			cout<<endl;
		}

		for(i=0;i<strlen(str);i++)
		{
			cout<<" ";
			for(j=1;j<=size;j++)
				if(te[str[i]-48][6]==1)	cout<<"-";
				else
					cout<<" ";
			for(j=1;j<=2;j++)
				cout<<" ";
		}
		cout<<endl;

		for(i=1;i<=size;i++)
		{
			for(j=0;j<strlen(str);j++)
			{
				if(te[str[j]-48][4]==1)
					cout<<"|";
				else
					cout<<" ";
				for(s=1;s<=size;s++)
					cout<<" ";
				if(te[str[j]-48][2]==1)
					cout<<"|";
				else
					cout<<" ";
				for(s=1;s<=1;s++)
					cout<<" ";
			}
			cout<<endl;
		}

		for(i=0;i<strlen(str);i++)
		{
			cout<<" ";
			for(j=1;j<=size;j++)
				if(te[str[i]-48][3]==1)	cout<<"-";
				else
					cout<<" ";
			for(j=1;j<=2;j++)
				cout<<" ";
		}
		cout<<endl<<endl;




	}

	return 0;
}
       

继续阅读