烟大 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 ...
随机推荐
- 基于REST架构的Web Service设计
来自: http://www.williamlong.info/archives/1728.html 先前我曾经介绍过利用Apache Axis实现基于SOAP的Web Service实现技术和相关代 ...
- 用开源Look&Feel (Substance)写 漂亮的Swing应用程序
今天用Swing 做了一个模仿QQ2009的登录界面,用到了开源的Look&Feel (Substance),在使用的过程中遇到了一些问题,也学到了一些技巧.Substance (https: ...
- Java JNI 编程进阶 实例+c++数据类型与jni数据类型转换
原文:http://www.iteye.com/topic/295776 JNI一直以来都很少去关注,但却是我心中的一个结,最近这几天刚好手头有点时间,因此抽空看了一下这方面的东西,整理了一份文档,J ...
- Zhulina 的高分子刷理论
高分子刷的解析平均场理论有两种表述方式.一个是MWC理论(Macromolecules 1988, 21, 2610-2619),另外一个就是Zhulina和Birshtein这两位俄罗斯老太太的理论 ...
- 在Linux用户空间做内核空间做的事情
导读 我相信,Linux 最好也是最坏的事情,就是内核空间(kernel space)和用户空间(user space)之间的巨大差别.如果没有这个区别,Linux 可能也不会成为世界上影响力最大的操 ...
- Mysql跨平台(Windows,Linux,Mac)使用与安装
MySQL其实是一个跨平台的轻量级数据库,平时开发会用到很多.有写程序可能要跨平台开发,接下来我就介绍一下如何跨平台使用Mysql. 这里所谓的跨平台就是Windows,Linux,Mac共同用一套M ...
- basic use of sidekiq
参考页面 https://github.com/mperham/sidekiq https://github.com/mperham/sidekiq/wiki/Getting-Started 强烈推荐 ...
- Apache同时支持PHP和Python的配置方法
一.http://www.oschina.net 网站中的一个问答内容: 原来把 WSGIScriptAlias / "D:/project/ddd/django.wsgi" ...
- BestCoder Round #60 1001
Problem Description You are given a sequence of NNN integers. You should choose some numbers(at leas ...
- HDOJ 1312 DFS&BFS
Red and Black Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...