烟大 Contest1024 - 《挑战编程》第一章:入门 Problem D: LC-Display(模拟计算器显示数字)
Problem D: LC-Display
Time Limit: 1 Sec Memory Limit: 64 MB
Submit: 14 Solved: 3
[Submit][Status][Web Board]
Description
A friend of yours has just bought a new computer. Before this, the most powerful machine he ever used was a pocket calculator. He is a little disappointed because he liked the LCD display of his calculator more than the screen on his new computer! To make him happy, write a program that prints numbers in LCD display style.
Input
The input file contains several lines, one for each number to be displayed. Each line contains integers s and n, where n is the number to be displayed ( 0n99, 999, 999) and s is the size in which it shall be displayed ( 1s10). The input will be terminated by a line containing two zeros, which should not be processed
Output
Print the numbers specified in the input file in an LCD display-style using s ``-'' signs for the horizontal segments and s ``|'' signs for the vertical ones. Each digit occupies exactly s + 2 columns and 2s + 3 rows. Be sure to fill all the white space occupied by the digits with blanks, including the last digit. There must be exactly one column of blanks between two digits. Output a blank line after each number. You will find an example of each digit in the sample output below.
Sample Input
Sample Output
-- -- --
| | | | | |
| | | | | |
-- -- -- --
| | | | |
| | | | |
-- -- -- --- --- --- --- ---
| | | | | | | |
| | | | | | | |
| | | | | | | |
--- --- ---
| | | | | | | |
| | | | | | | |
| | | | | | | |
--- --- --- ---
HINT
模拟题。这道题是在控制台中以计算器的显示形式显示指定尺寸大小的一串数字。
我的做法是提前写好数字的模板(因为尺寸不确定,所以要把数字做成模板),存放在一个三维数组中(数字,行,列)。输入尺寸和数字串后,将数字的模板组合起来,然后解析成指定尺寸的数字输出出来。
My code:
//这是一道模拟题
//模拟计算器的形式在控制台中输出数字 #include <iostream>
#include <string.h>
using namespace std; int a[][][]=
{
{//
,,,
,,,
,,,
,,,
,,
}
,{//
,,,
,,,
,,,
,,,
,,}
,{//
,,,
,,,
,,,
,,,
,,
}
,{//3
,,,
,,,
,,,
,,,
,,
}
,{//4
,,,
,,,
,,,
,,,
,,
}
,{//5
,,,
,,,
,,,
,,,
,,
}
,{//6
,,,
,,,
,,,
,,,
,,
}
,{//7
,,,
,,,
,,,
,,,
,,
}
,{//8
,,,
,,,
,,,
,,,
,,
}
,{//9
,,,
,,,
,,,
,,,
,,
}
};
/*
0是一个空格
1是size个竖杠
2是size个横杠
3是size个虚横杠
*/
int b[][];
int main()
{
string l;
int size;
while(cin>>size){
cin>>l;
if(size== && l=="") break;
int length=l.length();
//组合数字模板在数组b中
for(int i=;i<=;i++){ //循环行
int f=; //组合数组b的第一个开始赋值
for(int j=;j<=length;j++){ //循环数字
int num=l[j-]-'';
for(int k=;k<;k++){
b[i][f]=a[num][i-][k];
f++;
}
b[i][f]=;
f++;
}
}
/*输出组合好的数字模板
for(int i=1;i<=5;i++){
for(int j=1;j<=3*length+length-1;j++)
cout<<b[i][j];
cout<<endl;
}
*/
//将数字模板解析成数字
//0输出一个空格
//1输出size行竖杠
//2输出size个横杠
//3输出size行空格
int count = ;
for(int i=;i<=;i++){//循环行
for(int j=;j<=*length+length-;j++){
//if(j==3*length+length-1 && b[i][j]==0)
// continue;
if(i%!=){
switch(b[i][j]){
case :
cout<<' ';
break;
case :
for(int k=;k<size;k++)
cout<<'-';
break;
case :
for(int k=;k<size;k++)
cout<<' ';
break;
}
}
else{
switch(b[i][j]){
case :
cout<<' ';break;
case :
for(int k=;k<size;k++)
cout<<' ';
break;
case :
cout<<'|';break;
}
}
}
cout<<endl;
if(i%==){ //如果改行是偶数行,且输出次数再输出一遍
++count; //如果是偶数行,已经输出一遍了,count+1
if(count<size)
--i;
}
else
count=;
}
cout<<endl;
}
return ;
}
Freecode : www.cnblogs.com/yym2013
烟大 Contest1024 - 《挑战编程》第一章:入门 Problem D: LC-Display(模拟计算器显示数字)的更多相关文章
- ACM YTU 《挑战编程》第一章 入门 Problem E: Graphical Editor
Description Graphical editors such as Photoshop allow us to alter bit-mapped images in the same way ...
- Windows核心编程第一章.错误处理
Windows核心编程第一章,错误处理. 一丶错误处理 1.核心编程学习总结 不管是做逆向,开始做开发.在Windows下.你都需要看一下核心编程这本书.这本书确实写得很好.所以自己在学习这本书的同时 ...
- .NET Core实战项目之CMS 第一章 入门篇-开篇及总体规划
作者:依乐祝 原文地址:https://www.cnblogs.com/yilezhu/p/9977862.html 写在前面 千呼万唤始出来,首先,请允许我长吸一口气!真没想到一份来自28岁老程序员 ...
- net core体系-web应用程序-4asp.net core2.0 项目实战(CMS)-第一章 入门篇-开篇及总体规划
.NET Core实战项目之CMS 第一章 入门篇-开篇及总体规划 原文地址:https://www.cnblogs.com/yilezhu/p/9977862.html 写在前面 千呼万唤始出来 ...
- Java 面向对象编程——第一章 初识Java
第一章 初识Java 1. 什么是Java? Java是一种简单的.面向对象的.分布式的.解释的.安全的.可移植的.性能优异的多线程语言.它以其强安全性.平台无关性.硬件结构无关性.语言简 ...
- Java学习笔记 第一章 入门<转>
第一章 JAVA入门 一.基础常识 1.软件开发 什么是软件? 软件:一系列按照特定顺序组织的计算机数据和指令的集合 系统软件:DOS,Windows,Linux 应用软件:扫雷.QQ.迅雷 什么是开 ...
- windows核心编程-第一章 对程序错误的处理
第一章-对程序错误的处理 在开始介绍Microsoft Windows 的特性之前,必须首先了解 Wi n d o w s的各个函数是如何进行错误处理的. 当调用一个Wi n d o w s函数时,它 ...
- UNIX环境高级编程--第一章 UNIX基础知识
第一章 UNIX基础知识 1.2 UNIX体系结构 从严格意义上说,可将操作系统定义为一种软件,它控制计算机硬件资源,提供程序运行环境.我们将这种软件称为内核(kernel),因为 它相对较小,且 ...
- 读高性能JavaScript编程 第一章
草草的看完第一章,虽然看的是译文也是感觉涨姿势了, 我来总结一下: 由于 大多数浏览器都是 single process 处理 ui updatas and js execute 于是产生问题: js ...
随机推荐
- TCP的那些事儿(下)
TCP的那些事儿(下) 这篇文章是下篇,所以如果你对TCP不熟悉的话,还请你先看看上篇<TCP的那些事儿(上)> 上篇中,我们介绍了TCP的协议头.状态机.数据重传中的东西.但是TCP要解 ...
- ProcDump
https://technet.microsoft.com/en-us/sysinternals/dd996900.aspx
- [Angularjs]angular ng-repeat与js特效加载先后导致的问题
写在前面 最近在项目中遇到这样的一个前端的bug,在ng-repeat中绑定的图片,有一个晃动的特效,在手机端浏览的时候,图片有时候会正常展示,有时就展示不出来.当时猜测是因为angularjs与特效 ...
- ubuntu系统 用户进入后命令行只有一个“$” 美元符号
在新添加用户后,切换到该用户下面后: 发现命令行前面只有一个$符号,很不方便. 虽然每次输入一个bash可以解决,但是太麻烦. 如何解决呢? sudo vi /etc/passwd 找到该用户 wan ...
- 如何调试R程序(转载)
R语言的调试重要性不言而喻,这段时间准备改进一个R的包,但由于接触R时间不长,中间的很多东西不懂,需要重新打包调试,以对里面的很多程序有深入了解,下面从几个方面分享一下我的收获. 1.准备工作 a)R ...
- 最长公共子序列(LCS)
简单的DP. f[i][j]表示序列a中前i个中,序列b中前b个中,组成的最长公共子序列的长度. DP方程: if(a[i-1]==b[j-1]) f[i][j]=f[i-1][j-1]+1; el ...
- Centos 7 安装LAMP环境
一.安装Centos 官网下载Centos 7刻录成光盘后安装 二.安装apache yum install httpd #根据提示,输入Y安装即可成功安装 systemctl start httpd ...
- 题目1006:ZOJ问题
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:13212 解决:2214 题目描述: 对给定的字符串(只包含'z','o','j'三种字符),判断他是否能AC. 是否AC的规则如下:1. ...
- SpringMVC配置easyui-datagrid
SprimgMVC的UserController.java @RequestMapping(value = "listUserForJson") @ResponseBody pub ...
- RAID阵列的初始化与管理
如果我们创建RAID阵列的目的是新部署一台服务器,我们建议所有新创建的RAID阵列都应该做初始化操作,这样,硬盘上原有的用户数据将被清除,以便进行后续的系统,软件安装. 转自: http://zh.c ...