OPENJUDGE 2745 显示器

本文介绍了一个使用 C++ 编写的程序,该程序能够接收输入的数字和显示大小,然后将数字以特定的格式打印出来。每个数字由不同的符号组成,通过调整显示大小可以改变输出的视觉效果。

Just Do it!

Whatever.....

# include <iostream>
# include <string>

using namespace std;

//string line[11][3] = {{"-"," ","-"},{" "," "," "},{"-","-","-"},{"-","-","-"},{" "," "," "},{"-","-","-"},{"-","-","-"},{"-",

void Display(int displaySize, string& s)
{
	int stringLen = s.length();
	int i = 0;
	int j = 0;
	int k = 0;
	int lineRepeat = displaySize;
	//Display Line 1
	for ( i = 0; i < stringLen; i++ )
	{
		cout << " ";
		for ( j = 0; j < displaySize; j++ )
		{
			if ( s[i] == '0' || s[i] == '2' || s[i] == '3' || s[i] >= '5' )
			{
				cout << "-";
			}
			else cout << " ";
		}
		cout << " ";
		cout << " "; //The space between numbers
	}
	cout << endl;

	//Display line 2
	for ( i = 0; i < lineRepeat; i++ )
	{
		for ( j = 0; j < stringLen; j++ )
		{
			if ( s[j] == '1' || s[j] == '2' || s[j] == '3' || s[j] == '7' )
			{
				cout << " ";
			}
			else cout << "|";
			for ( k = 0; k < displaySize; k++ )
			{
				cout << " ";
			}
			if ( s[j] == '5' || s[j] == '6' )
			{
				cout << " ";
			}
			else cout << "|";	
			cout << " ";
		}
		cout << endl;
	}

	//Display line 3
	for ( i = 0; i < stringLen; i++ )
	{
		cout << " ";
		for ( j = 0; j < displaySize; j++ )
		{
			if ( s[i] == '2' || s[i] == '3' || s[i] == '4' || s[i] == '5' || s[i] == '6' || s[i] == '8' || s[i] == '9' )
			{
				cout << "-";
			}
			else cout << " ";
		}
		cout << " ";
		cout << " "; //The space between numbers
	}
	cout << endl;

	//Display line 4
	for ( i = 0; i < lineRepeat; i++ )
	{
		for ( j = 0; j < stringLen; j++ )
		{
			if ( s[j] == '1' || s[j] == '3' || s[j] == '4' || s[j] == '5' || s[j] == '7' || s[j] == '9' )
			{
				cout << " ";
			}
			else cout << "|";
			for ( k = 0; k < displaySize; k++ )
			{
				cout << " ";
			}
			if ( s[j] == '2' )
			{
				cout << " ";
			}
			else cout << "|";	
			cout << " ";
		}
		cout << endl;
	}

	//Display Line 5
	for ( i = 0; i < stringLen; i++ )
	{
		cout << " ";
		for ( j = 0; j < displaySize; j++ )
		{
			if ( s[i] == '0' || s[i] == '2' || s[i] == '3' || s[i] == '5' || s[i] == '6' || s[i] == '8' || s[i] == '9' )
			{
				cout << "-";
			}
			else cout << " ";
		}
		cout << " ";
		cout << " "; //The space between numbers
	}
	cout << endl;

}

int main()
{
	int displaySize = 0;
	string inputString;
	while ( cin >> displaySize >> inputString )
	{
		if ( displaySize == 0 && inputString == "0" )
		{
			break;
		}
		Display(displaySize,inputString);
		cout << endl;
	}
	return 0;
}


评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值