放牧代码和思想
专注自然语言处理、机器学习算法
    This thing called love. Know I would've. Thrown it all away. Wouldn't hesitate.

UVa Q706: LC-Display

模拟类。还是那种纯码农人肉级别的题目。

Q706: LC-Display

你的一个朋友最近买了一部新电脑,在这之前,他只用过口袋型计算机。现在他对这新电脑有点失望,因为他非常喜欢以前计算机显示数字的样式,而不是像现在新电脑所显示的。所以你的任务是写一个程式帮他把数字以计算机上数字的样式显现出来。

Input

每笔测试资料一列。每列有2个整数s,n(1 <= s <= 10, 0 <= n <= 99999999)。n是要显示的数字,s是每个字要求的大小。s=0, n=0代表输入结束。

Output

请以计算机的数字样式,并以s的大小显示n。这些计算机数字是以'-'当作水平线,以'|'当作垂直线所构成,并且每个数字的大小宽为s+2,高为2s+3。数字0~9的样式请参考Sample Outpu,请注意:在2个数字中间有一空白行。

每组测试资料后亦请空一列。

Sample Input

1 0123456789
2 12345
3 67890

Sample Output

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

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

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

简体中文由Lucky貓的 UVA(ACM)園地转换。

看完这道题,第一反应就是,误交损友啊!

需要注意几点:

  1. 每一位数字之间都有一个空格,但是最后一个却没有,很容易看漏

  2. 没一个数字输出后要空一行

  3. 输入数字不能用int,因为有前导0

我就是因为没注意到1、2两点所以浪费了点时间检查。

#ifndef ONLINE_JUDGE
#pragma warning(disable : 4996)
#endif
#include <iostream>
#include <string>
using namespace std;

int s = 0;
string n;

int Font[10][15] = {
	  { 0, 1, 0 ,
		1, 0, 1 ,
		0, 0, 0 ,
		1, 0, 1 ,
		0, 1, 0 },

	  { 0, 0, 0 ,
	    0, 0, 1 ,
	    0, 0, 0 ,
	    0, 0, 1 ,
	    0, 0, 0 },

	  { 0, 1, 0 ,
		0, 0, 1 ,
		0, 1, 0 ,
		1, 0, 0 ,
		0, 1, 0 },

	  { 0, 1, 0 ,
		0, 0, 1 ,
	    0, 1, 0 ,
	    0, 0, 1 ,
	    0, 1, 0 },
		  
	  { 0, 0, 0 ,
		1, 0, 1 ,
		0, 1, 0 ,
		0, 0, 1 ,
		0, 0, 0 },

	  { 0, 1, 0 ,
		1, 0, 0 ,
		0, 1, 0 ,
		0, 0, 1 ,
		0, 1, 0 },
		
	  { 0, 1, 0,
		1, 0, 0,
		0, 1, 0,
		1, 0, 1,
		0, 1, 0 },
	  
	  { 0, 1, 0,
		0, 0, 1,
		0, 0, 0,
		0, 0, 1,
		0, 0, 0 },

	  { 0, 1, 0,
		1, 0, 1,
		0, 1, 0,
		1, 0, 1,
		0, 1, 0 },

	  { 0, 1, 0,
		1, 0, 1,
		0, 1, 0,
		0, 0, 1,
		0, 1, 0 },
};

//************************************
// Method:    print_line_of_digit
// FullName:  print_line_of_digit
// Access:    public 
// Returns:   void
// Qualifier:
// Parameter: const int & n which digit
// Parameter: const int & h height, 0 ~ 4
//************************************
void print_line_of_digit(const int& n, const int& h)
{
	if (Font[n][3 * h + 0])
	{
		cout << '|';
	}
	else
	{
		cout << ' ';
	}

	if (Font[n][3 * h + 1])
	{
		for (int j = 0; j < s; ++j)
		{
			cout << '-';
		}
	}
	else
	{
		for (int j = 0; j < s; ++j)
		{
			cout << ' ';
		}
	}

	if (Font[n][3 * h + 2])
	{
		cout << '|';
	}
	else
	{
		cout << ' ';
	}
}

///////////////////////////SubMain//////////////////////////////////
int main(int argc, char *argv[])
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	while (cin >> s >> n && s)
	{
		int count = n.length();

		for (int i = 0; i < count; ++i)
		{
			int current_n = n[i] - '0';
			print_line_of_digit(current_n, 0);
			if (i != count - 1)
			{
				cout << ' ';
			}
		}
		cout << endl;

		for (int j = 0; j < s; ++j)
		{
			for (int i = 0; i < count; ++i)
			{
				int current_n = n[i] - '0';
				print_line_of_digit(current_n, 1);
				if (i != count - 1)
				{
					cout << ' ';
				}
			}
			cout << endl;
		}

		for (int i = 0; i < count; ++i)
		{
			int current_n = n[i] - '0';
			print_line_of_digit(current_n, 2);
			if (i != count - 1)
			{
				cout << ' ';
			}
		}
		cout << endl;

		for (int j = 0; j < s; ++j)
		{
			for (int i = 0; i < count; ++i)
			{
				int current_n = n[i] - '0';
				print_line_of_digit(current_n, 3);
				if (i != count - 1)
				{
					cout << ' ';
				}
			}
			cout << endl;
		}

		for (int i = 0; i < count; ++i)
		{
			int current_n = n[i] - '0';
			print_line_of_digit(current_n, 4);
			if (i != count - 1)
			{
				cout << ' ';
			}
		}
		cout << endl;
		cout << endl;
	}
#ifndef ONLINE_JUDGE
	fclose(stdin);
	fclose(stdout);
	system("out.txt");
#endif
	return 0;
}
///////////////////////////End Sub//////////////////////////////////

知识共享许可协议 知识共享署名-非商业性使用-相同方式共享码农场 » UVa Q706: LC-Display

评论 欢迎留言

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

我的作品

HanLP自然语言处理包《自然语言处理入门》