UVA 706 LCD Display 液晶显示屏 (字符串模拟)

题目链接click here~~

题目大意

给定的数字序列,按照要求输出对应液晶显示屏上的数字

输入:

2 12345
3 67890
0 0

输出:

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

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

解题思路

模拟,考的就是细心了,先将n拆分为单个的数字,用一个数组存起来 ,定义每个数字的关键笔划,可以知道之后的笔画其实就是重复之前的笔画!

代码:

/*
Author :HRW
UVA 706
字符串模拟
思路:先将n拆分为单个的数字,用一个数组存起来
       定义每个数字的关键笔划,可以知道之后的笔画其实就是重复之前的笔画!
*/
#include <bits/stdc++.h>
using namespace std;
void AC(int s,int n)
{
    int a[8];
    memset(a,-1,sizeof(a)); // 将n拆分为单个的数字。
    if(n==0) a[7]=0;
    else{
        for(int i=7;n>0; i--){
          a[i]=n%10;
          n/=10;
        }
    }                       // 定义每个数字的关键笔划。
    string  str[5][10]={
        " - ", "   ", " - ", " - ", "   ", " - ", " - ", " - ", " - ", " - ",
        "| |", "  |", "  |", "  |", "| |", "|  ", "|  ", "  |", "| |", "| |",
        "   ", "   ", " - ", " - ", " - ", " - ", " - ", "   ", " - ", " - ",
        "| |", "  |", "|  ", "  |", "  |", "  |", "| |", "  |", "| |", "  |",
        " - ", "   ", " - ", " - ", "   ", " - ", " - ", "   ", " - ", " - "
    };
                           // 将关键笔划扩大显示,从上到下分成5块,依次判断,实际上就是将关键笔划重复。
    for(int i=1;i<=(s*2+3);i++){
        for(int j=0;j<8;j++){
            if(a[j]!=-1){
            string ss;
            if(i==1) ss=str[0][a[j]];
            if(2<=i&&i<s+2)ss=str[1][a[j]];
            if(i==(s+2)) ss=str[2][a[j]];
            if(s+3<=i&&i<=(2*s+2)) ss=str[3][a[j]];
            if(i==(2*s+3)) ss=str[4][a[j]];
            cout<<ss[0];        // 输出关键笔划。
            for(int k=0;k<s;k++)
            cout<<ss[1];
            cout<<ss[2];
            if(j<7) cout<<" "; // 在两个数字间要有一列空行。
            }
       }
          cout<<endl;
    }
}
int main()
{
   //freopen("1.txt","r",stdin);
   int s,n;
   while(cin>>s>>n)
   {
       if(s==0&&n==0) break;
       AC(s,n);
       cout<<endl;
   }
   return 0;
}
时间: 2024-10-12 19:23:18

UVA 706 LCD Display 液晶显示屏 (字符串模拟)的相关文章

UVA 10815-Andy&#39;s First Dictionary(字符串模拟+排序+重复删除)

Andy's First Dictionary Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Description Problem B: Andy's First Dictionary Time limit: 3 seconds Andy, 8, has a dream - he wants to produce his very own dictionary. This

【UVA】230 - Borrowers(map模拟)

利用map<string,int>判断一本书的状态,0代表借出去了,1代表在书架,2代表借出去换回来但是还未放回书架 设计一些字符串的处理问题,用一些字符串搜索函数比如 strstr , strchar等等 14072706 230 Borrowers Accepted C++ 0.015 2014-08-21 02:59:27 AC代码: #include<cstdio> #include<cstring> #include<iostream> #incl

uva 10391 Compound Words (字符串-hash)

Problem E: Compound Words You are to find all the two-word compound words in a dictionary. A two-word compound word is a word in the dictionary that is theconcatenation of exactly two other words in the dictionary. Input Standard input consists of a

uva--1368(贪心,字符串模拟)

点击打开链接 该题是一个带有贪心思想的字符串模拟题,题目给定m个长度为n的字符串,让你求一个长度为n的字符串,使得该字符串与这m个字符串对应位置的字符不同的个数和最小. 要使对应位置不同字符最少,则该字符串每个字符优先选择该位置出现次数多的字符,若次数相同则选择字典序更小的字符. 代码: #include <iostream> #include <cstdio> #include <string.h> #include <map> #include <

hdu 4119 Isabella&#39;s Message【字符串模拟】

题目链接:http://write.blog.csdn.net/postedit 自我感觉比较麻烦 #include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> #include<string> #include<map> using namespace std; const int maxh=100+10; const int maxe=100

大数运算之字符串模拟

相信大家被特别大的两个数据做运算折磨过.当两个操作数或者运算结果超过类型的表示范围后会有意想不到的错误,这时候我们的电脑还不如我们高中用过的科学计算器,这是作为一个程序员所不能忍受的.所以我们得找到其他的方式来计算.这就是我们今天要讨论的字符串模拟大数运算. 我们的运算一般使用int类型来算的,那么首先我们先复习一下各种int类型的数据表示范围: unsigned int 0-4294967295    int   -2147483648-2147483647  unsigned long 0-

从1打印到最大的n位数字(字符串模拟数字自加)

陷阱:  用最大的n位数-1(数字太大可能产生越界) 应该采用字符串模拟数字自加! 代码如下: #include<iostream> using namespace std; int  IsMax(char *number) {  int nLength = strlen(number);  int CarryBit = 0;  bool  ret = false;  for (int i = nLength-1; i >= 0; i--)  {   int nSum = number[

uva 10881 Piotr&#39;s Ants (模拟)

uva 10881 Piotr's Ants "One thing is for certain: there is no stopping them; the ants will soon be here. And I, for one, welcome our new insect overlords."Kent Brockman Piotr likes playing with ants. He has n of them on a horizontal pole L cm lo

UVA 10881 - Piotr&#39;s Ants【模拟+思维】

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1822 题意:有很多只蚂蚁在一条直线上,每个蚂蚁移动速度都是1,并且有一个初始方向.并且当相邻两个蚂蚁相撞时转向.现在问t时间后各个蚂蚁的位置. 解法:这题的一个致命技巧就是把两只蚂蚁的相撞看作是两只蚂蚁交换穿过对方并且交换蚂蚁的编号.这个是很好理解的,类似于物理的完全弹性碰撞.又由