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的人有直接或间接关系的人数 ...
随机推荐
- 自定义select控件开发
目的:select下拉框条目太多(上百),当用户选择具体项时会浪费用户很多时间去寻找,因此需要一个搜索框让用户输入关键字来匹配列表,便于用户选择 示例图: 1.html结构 <div class ...
- Slave_SQL_Running: No mysql同步故障解决方法
Slave_SQL_Running: No mysql同步故障解决 今天检查数据库发现一台MySQL Slave未和主机同步,查看Slave状态:mysql> show slave s ...
- 你可能不知道的Google Chrome命令行参数
概述: 关于Google Chrome命令行参数(英文叫Google Chrome Command line switches),是Chrome为了实现实验性功能.方便调试. ...
- 清北学堂模拟day4 捡金币
[问题描述]小空正在玩一个叫做捡金币的游戏.游戏在一个被划分成 n行 n列的网格状场地中进行.每一个格子中都放着若干金币,并且金币的数量会随着时间而不断变化. 小空的任务就是在网格中移动,拾取尽量多的 ...
- 大数据BI积累
http://blog.csdn.net/wyzxg/article/category/535869 设计论文:http://www.doc88.com/p-3877368345851.html 自动 ...
- springmvc之图片上传
1.接收到的是图片的流时 //上传头像 @RequestMapping(value = "/uploadHeadSculpture", method = RequestMethod ...
- 从程序员到CTO的Java技术路线图
转自:http://zz563143188.iteye.com/blog/1877266 企业级项目实战地址:http://zz563143188.iteye.com/blog/1825168 开发资 ...
- WWDC15 Session笔记 - Xcode 7 UI 测试初窥
https://onevcat.com/2015/09/ui-testing/ WWDC15 Session笔记 - Xcode 7 UI 测试初窥 Unit Test 在 iOS 开发中已经有足够多 ...
- linux中diff命令用法
diff 命 令是 linux上非常重要的工具,用于比较文件的内容,特别是比较两个版本不同的文件以找到改动的地方.diff在命令行中打印每一个行的改动.最新版 本的diff还支持二进制文件.diff程 ...
- Python自动化之多进程
多进程multiprocessing from multiprocessing import Process import os def info(title): print(title) print ...