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的人有直接或间接关系的人数 ...
随机推荐
- CF459A Pashmak and Garden (水
Pashmak and Garden Codeforces Round #261 (Div. 2) A. Pashmak and Garden time limit per test 1 second ...
- oracle 中的dual表简介与用法
Dual表是每个数据库创建时默认生成的,该表仅有一列一行. 1)分析dual表执行,如下:
- Mastering Web Application Development with AngularJS 读书笔记(二)
第一章笔记 (二) 一.scopes的层级和事件系统(the eventing system) 在层级中管理的scopes可以被用做事件总线.AngularJS 允许我们去传播已经命名的事件用一种有效 ...
- [译]git status
git status git status命令能展示工作目录和stage区的状态. 使用他你能看到那些修改被staged到了, 哪些没有, 哪些文件没有被Git tracked到. git statu ...
- tyvj1614 魔塔魔塔!
描述 百度noip贴吧管理组开发了一个小游戏,叫魔塔魔塔.虽然把魔塔重复了两次,但其实还只是个魔塔而已,还是简化版的.游戏在一个N*M大小的地图中进行,每一格都是正方形.对于某一格,有若干种可能的状态 ...
- Linux 下复制(cp)目录时排除一个或者多个目录的方法
cp 貌似没有排除目录的功能,可以使用 rsync 命令来实现了,如: [案例] /home/52php目录里面有data目录,data目录里面有 a.b.c.d.e 五个目录,现在要把data目录里 ...
- git之常用指令
参考:Git教程 - 廖雪峰的官方网站 1.git //linux上检测是否安装git 2.sudo apt-get install git //linux上安装git 3.git config - ...
- nginx命令
window cmd 到nginx的文件夹 start nginx 启动命令 nginx -s reload 重新启动 nginx -s stop 关闭 linux 到 sbin ...
- C#字符串和数据之间的转换
c#中不仅仅存在数值类型的数据之间的转换,字符串和数值之间也是可以互相转换的,只是方法不同而已. 1 数值型转换为字符型 数值型数据转换为字符串用ToString()方法即可实现 int num1=1 ...
- r-cnn学习(二)
faster r-cnn 1.问题 在fast r-cnn中,proposals已经成为速度提高的瓶颈.在本文中,使用深度网络来计算proposals, 使得与检测网络的计算量相比,proposals ...