poj 1102.LC-Display 解题报告
题目链接:http://poj.org/problem?id=1102
题目意思:就是根据给出的格式 s 和 数字 n,输出数值 n 的 LCD 显示。数值 n 的每个数字要占据 s + 2 列 和 2s + 3 行。数字和数字之间要有一个空格。数值与数值之间有一个空行。
首先对于LCD 的 7 个笔画显示编上序号

然后对于数字 i,分析出占用了哪几个笔画,例如,数字 1 占有的笔画是 3 和 6;数字 6 占有的笔画是 1, 2, 4, 5, 6, 7
用数组来存储每一个笔画分别被那些数字占有,如果是打横的笔画,就放在 horizontal[][] 上;打竖的笔画放在 vertical[][]。然后根据数值 n 来根据对应的horizontal[][] 和 vertical[][] 的占有情况来输出。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; const int maxrow = + ;
const int maxcol = + ; // 数字0~9占有的笔画编号
// 打横的笔画,笔画编号分别为: 1 4 7
char horizontal[maxrow][maxcol] = {"- -- -----", " ----- --", "- -- -- --"};
// 打竖的笔画,笔画编号分别为: 2 3 5 6
char vertical[maxrow][maxcol] = {"| ||| ||", "||||| |||", "| | | | ", "|| |||||||"};
char n[maxcol];
int s, len; void get_horizontal(int row)
{
for (int j = ; j < len; j++)
{
printf(" ");
for (int i = ; i <= s; i++)
printf("%c", horizontal[row][n[j]-'']);
printf(" ");
}
} void get_vertical(int row)
{
for (int j = ; j < len; j++)
{
printf("%c", vertical[row][n[j]-'']);
for (int i = ; i <= s; i++)
printf(" ");
printf("%c ", vertical[row+][n[j]-'']);
}
} int main()
{
#ifndef Online_Judge
freopen("in.txt", "r", stdin);
#endif // Online_Judge
while (scanf("%d%s", &s, n) != EOF)
{
if (s == && !strcmp(n, ""))
break;
len = strlen(n);
for (int i = ; i <= *s+; i++) // 共 2s+3 行
{
if (i == ) // 第 1 行 打横的笔画
get_horizontal();
else if (i > && i < s+) // 第 2 ~ s+1 行 打竖的笔画
get_vertical();
else if (i == s+) // 第 s+2 行 打横的笔画
get_horizontal();
else if (i > s+ && i < *s+) // 第 s+3 ~ 2s+2 行 打竖的笔画
get_vertical();
else
get_horizontal(); // 第 2s+3 行 打横的笔画
printf("\n");
}
printf("\n");
}
printf("\n"); // 这个空行是是否 wa 的关键!要特别小心 = =
return ;
}
poj 1102.LC-Display 解题报告的更多相关文章
- Tarjan算法求解桥和边双连通分量(附POJ 3352 Road Construction解题报告)
http://blog.csdn.net/geniusluzh/article/details/6619575 在说Tarjan算法解决桥和边双连通分量问题之前我们先来回顾一下Tarjan算法是如何 ...
- POJ 3126 Prime Path 解题报告(BFS & 双向BFS)
题目大意:给定一个4位素数,一个目标4位素数.每次变换一位,保证变换后依然是素数,求变换到目标素数的最小步数. 解题报告:直接用最短路. 枚举1000-10000所有素数,如果素数A交换一位可以得到素 ...
- 【原创】poj ----- 2376 Cleaning Shifts 解题报告
题目地址: http://poj.org/problem?id=2376 题目内容: Cleaning Shifts Time Limit: 1000MS Memory Limit: 65536K ...
- 【原创】poj ----- 1611 The Suspects 解题报告
题目地址: http://poj.org/problem?id=1611 题目内容: The Suspects Time Limit: 1000MS Memory Limit: 20000K To ...
- 【原创】poj ----- 2524 Ubiquitous Religions 解题报告
题目地址: http://poj.org/problem?id=2524 题目内容: Ubiquitous Religions Time Limit: 5000MS Memory Limit: 6 ...
- [POJ 1002] 487-3279 C++解题报告
487-3279 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 228365 Accepted: 39826 D ...
- [POJ 1001] Exponentiation C++解题报告 JAVA解题报告
Exponentiation Time Limit: 500MS Memory Limit: 10000K Total Submissions: 126980 Accepted: 30 ...
- poj 2389.Bull Math 解题报告
题目链接:http://poj.org/problem?id=2389 题目意思:就是大整数乘法. 题目中说每个整数不超过 40 位,是错的!!!要开大点,这里我开到100. 其实大整数乘法还是第一次 ...
- poj 2421 Constructing Roads 解题报告
题目链接:http://poj.org/problem?id=2421 实际上又是考最小生成树的内容,也是用到kruskal算法.但稍稍有点不同的是,给出一些已连接的边,要在这些边存在的情况下,拓展出 ...
- poj 1611 The Suspects 解题报告
题目链接:http://poj.org/problem?id=1611 题意:给定n个人和m个群,接下来是m行,每行给出该群内的人数以及这些人所对应的编号.需要统计出跟编号0的人有直接或间接关系的人数 ...
随机推荐
- php各种编码集详解和以及在什么情况下进行使用
字符是各种文字和符号的总称,包括各国家文字.标点符号.图形符号.数字等. 字符集是多个字符的集合,字符集种类较多,每个字符集包含的字符个数不同,常见字符集名称:ASCII字符集.GB2312字符集.B ...
- oracle 中的dual表简介与用法
Dual表是每个数据库创建时默认生成的,该表仅有一列一行. 1)分析dual表执行,如下:
- Linux下查看文件内容的命令
查看文件内容的命令: cat 由第一行开始显示内容,并将所有内容输出 tac 从最后一行倒序显示内容,并将所有内容输出 more 根据窗口大小,一页一页的现实文件内容 less ...
- godaddy空间的sql server数据库没办法insert中文
原来的代码: use string007 from sysobjects where id = object_id('K_V_TEST') and type = 'U') drop table K_V ...
- iOS原生的搜索:UISearchController
iOS8之前我们使用UISearchDisplayController做TableView的本地搜索,查看UIKit库,苹果已经使用新控件取代它. NS_CLASS_DEPRECATED_IOS(3_ ...
- C#之类与对象
这段代码告诉我们要把#define DEBUG放在文件的开头位置,不然会导致编译错误,最后还要#endif 以上代码告诉我们可以对自己创建的类设计自己的构造方法,然后可以通过具体的Main()函数来通 ...
- windows server 2008 R2 SP1 安装exchange 2010
一. 先决条件 若在windows server R2 SP1企业版系统上典型安装exchange server2010 SP3,则需要提前确定一下先决条件 AD域环境,域和林的功能级别必须是wind ...
- canvas对象arcTo函数的使用-遁地龙卷风
(-1)环境说明 我使用的浏览器是chrome49 (1)详细介绍 $(function() { var context = lol.getContext("2d"); conte ...
- hdu4747——Mex
1.题目大意:对一个序列的每一个区间求Mex,最后所有的mex相加(mex就是SG的那个),力求nlogn... 2.分析:最近开始刷线段树了,还是有很多不会啊 首先把1-1 1-2 1-- 1-n这 ...
- 获取action name在asp.net mvc
Update for MVC 3 ViewContext.Controller.ValueProvider.GetValue("action").RawValue ViewCont ...