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

2 12345
3 67890
0 0

Sample Output

      --   --        --
| | | | | |
| | | | | |
-- -- -- --
| | | | |
| | | | |
-- -- -- --- --- --- --- ---
| | | | | | | |
| | | | | | | |
| | | | | | | |
--- --- ---
| | | | | | | |
| | | | | | | |
| | | | | | | |
--- --- --- ---

HINT

杭电1332


  模拟题。这道题是在控制台中以计算器的显示形式显示指定尺寸大小的一串数字。

  我的做法是提前写好数字的模板(因为尺寸不确定,所以要把数字做成模板),存放在一个三维数组中(数字,行,列)。输入尺寸和数字串后,将数字的模板组合起来,然后解析成指定尺寸的数字输出出来。

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(模拟计算器显示数字)的更多相关文章

  1. ACM YTU 《挑战编程》第一章 入门 Problem E: Graphical Editor

    Description Graphical editors such as Photoshop allow us to alter bit-mapped images in the same way ...

  2. Windows核心编程第一章.错误处理

    Windows核心编程第一章,错误处理. 一丶错误处理 1.核心编程学习总结 不管是做逆向,开始做开发.在Windows下.你都需要看一下核心编程这本书.这本书确实写得很好.所以自己在学习这本书的同时 ...

  3. .NET Core实战项目之CMS 第一章 入门篇-开篇及总体规划

    作者:依乐祝 原文地址:https://www.cnblogs.com/yilezhu/p/9977862.html 写在前面 千呼万唤始出来,首先,请允许我长吸一口气!真没想到一份来自28岁老程序员 ...

  4. net core体系-web应用程序-4asp.net core2.0 项目实战(CMS)-第一章 入门篇-开篇及总体规划

    .NET Core实战项目之CMS 第一章 入门篇-开篇及总体规划   原文地址:https://www.cnblogs.com/yilezhu/p/9977862.html 写在前面 千呼万唤始出来 ...

  5. Java 面向对象编程——第一章 初识Java

      第一章    初识Java 1.  什么是Java? Java是一种简单的.面向对象的.分布式的.解释的.安全的.可移植的.性能优异的多线程语言.它以其强安全性.平台无关性.硬件结构无关性.语言简 ...

  6. Java学习笔记 第一章 入门<转>

    第一章 JAVA入门 一.基础常识 1.软件开发 什么是软件? 软件:一系列按照特定顺序组织的计算机数据和指令的集合 系统软件:DOS,Windows,Linux 应用软件:扫雷.QQ.迅雷 什么是开 ...

  7. windows核心编程-第一章 对程序错误的处理

    第一章-对程序错误的处理 在开始介绍Microsoft Windows 的特性之前,必须首先了解 Wi n d o w s的各个函数是如何进行错误处理的. 当调用一个Wi n d o w s函数时,它 ...

  8. UNIX环境高级编程--第一章 UNIX基础知识

    第一章 UNIX基础知识 1.2 UNIX体系结构   从严格意义上说,可将操作系统定义为一种软件,它控制计算机硬件资源,提供程序运行环境.我们将这种软件称为内核(kernel),因为 它相对较小,且 ...

  9. 读高性能JavaScript编程 第一章

    草草的看完第一章,虽然看的是译文也是感觉涨姿势了, 我来总结一下: 由于 大多数浏览器都是 single process 处理 ui updatas and js execute 于是产生问题: js ...

随机推荐

  1. springmvc中@PathVariable和@RequestParam的区别(百度收集)

    http://localhost:8080/Springmvc/user/page.do?pageSize=3&pageNow=2 你可以把这地址分开理解,其中问号前半部分:http://lo ...

  2. 看了让人笑了很多很多次的NB的痔疮经历

    前言 这篇杂记其实是去年也就是 2013年9月30日转载的,后来在整理博客分类时七弄八弄误删掉了好多文章,就包括这一篇.今天,2014年9月29日,恰好恰好一年的时候居然在好久未登陆的 OneNote ...

  3. sql重复记录查询

    1.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断 select * from people where peopleId in (select  peopleId  fro ...

  4. 为dedecms文章列表页标题增加序号,第二页开始才显示第x页

    想必大伙建站都会写文章,随着时间的推移,你的智慧结晶会越来越多,一般的建站程序早帮你想好了,把这些文章做成一个列表,比如dedecms栏目列表,便于观众浏览,但有个问题就是dedecms文章列表页标题 ...

  5. [Effective JavaScript 笔记]第3章:使用函数--个人总结

    前言 这一章把平时会用到,但不会深究的知识点,分开细化地讲解了.里面很多内容在高3等基础内容里,也有很多讲到.但由于本身书籍的篇幅较大,很容易忽视对应的小知识点.这章里的许多小提示都很有帮助,特别是在 ...

  6. 用Lucene检索数据库

    http://blog.sina.com.cn/s/blog_82ac67c101012r9z.html package com.javabean; import java.io.File;impor ...

  7. ubuntu 快速安装jre

    sudo add-apt-repository ppa:webupd8team/java sudo apt-get update sudo apt-get install oracle-java7-i ...

  8. 开博一周总结与随谈[thinking of writing blog for one week]

    8天前,就是5月19号,突发奇想,觉得应该开个博客记录下自己的学习笔记和心得,更重要的是做个自我梳理和总结.大致看了下国内的博客,最后选定cnblogs.之所以选则cnblogs是因为平时搜到不少好文 ...

  9. iOS 定义圆角控件

    ios7 以前,想把UILabel变为圆角的,只需要设置layer的 cornerRadius属性,ios7以后,还需要设置 masksToBounds = true. 以下是这个属性的说明 A Bo ...

  10. Java web项目的字符集问题

    如果在Windows系统下使用eclipse开发Java应用,那么开始的时候我们一般不会考虑编码问题,但是随着不断学习,接触到前端.服务端.数据接口.数据库等更多的组件时,编码问题就逐渐暴露出来了,我 ...