UVA 706 LCD

为什么打印出来是两个分隔的竖线???

真心给跪了。。。、

#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <cctype>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <map>
#include <stack>
#include <list>
#include <iomanip>
using namespace std;
///
#define INF 0xffffff7
#define maxn 10010
///
//下面为0~9字符表示
int P[10][7] = {
	{1, 1, 1, 0, 1, 1, 1},
	{0, 0, 1, 0, 0, 1, 0},
	{1, 0, 1, 1, 1, 0, 1},
	{1, 0, 1, 1, 0, 1, 1},
	{0, 1, 1, 1, 0, 1, 0},
	{1, 1, 0, 1, 0, 1, 1},
	{1, 1, 0, 1, 1, 1, 1},
	{1, 0, 1, 0, 0, 1, 0},
	{1, 1, 1, 1, 1, 1, 1},
	{1, 1, 1, 1, 0, 1, 1}
};
void printRow(int s, int num, int rank)
{
	int i, j;
	if (rank == 1)
	{
		if (P[num][0] == 0)
		{
			for (i = 0; i < s + 2; i++)
				printf(" ");
		}
		else
		{
			for (i = 0; i < s + 2; i++)
			{
				if (i == 0 || i == s + 1)
					printf(" ");
				else
					printf("-");
			}
		}
	}
	if (rank == 3)
	{
		if (P[num][3] == 0)
		{
			for (i = 0; i < s + 2; i++)
				printf(" ");
		}
		else
		{
			for (i = 0; i < s + 2; i++)
			{
				if (i == 0 || i == s + 1)
					printf(" ");
				else
					printf("-");
			}
		}
	}
	if (rank == 5)
	{
		if (P[num][6] == 0)
		{
			for (i = 0; i < s + 2; i++)
				printf(" ");
		}
		else
		{
			for (i = 0; i < s + 2; i++)
			{
				if (i == 0 || i == s + 1)
					printf(" ");
				else
					printf("-");
			}
		}
	}

}
void printfCol(int s, int num,int  rank)
{
	int i, j;
	if (rank == 2)
	{
		if (P[num][1] == 1)
			printf("|");  //为什么打印出来是分隔的两个竖线?
		else
			printf(" ");
		for (i = 1; i <= s; i++)
			printf(" ");
		if (P[num][2] == 1)
			printf("|");
		else
			printf(" ");
	}
	if (rank == 4)
	{
		if (P[num][4] == 1)
			printf("|");
		else
			printf(" ");
		for (i = 1; i <= s; i++)
			printf(" ");
		if (P[num][5] == 1)
			printf("|");
		else
			printf(" ");
	}

}
char num[20];
int main()
{
	///
	int i, j, k;
	int s;
	while (1)
	{
		scanf("%d", &s);
		if (s == 0)
			break;
		scanf("%s", num);
		int len = strlen(num);
		//一共输出广义5行  1 + s + 1 + s + 1行
		for (i = 1; i <= 5; i++)
		{
			//如果是奇数行
			if (i % 2 == 1)
			{
				//一共len个字符,每个字符采用printRow函数输出,字符之间输出空格
				for (j = 0; j < len; j++)
				{
					int tempNum;
					tempNum = num[j] - '0';
					printRow(s, tempNum, i);

					if (j != len - 1)
						printf(" "); //最后一个数后面不输出空格
				}
				if (i != 5)
					printf("\n");//输出一个空行
			}
			//如果是偶数行s
			else
			{
				for (j = 0; j < s; j++)
				{
					//一共len个字符
					for (k = 0; k < len; k++)
					{
						int tempNum = num[k] - '0';
						printfCol(s, tempNum, i);

						if (k != len - 1)
							printf(" ");
					}
					printf("\n");//输出一个空行
				}

			}
		}
		printf("\n");
	}
	
    ///
    return 0;
	
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值