现在的位置: 首页 > 综合 > 正文

Time(山东理工OJ)

2014年10月24日 ⁄ 综合 ⁄ 共 2000字 ⁄ 字号 评论关闭

题目描述
Digital clock use 4 digits to express time, each digit is described by 3*3 characters (including”|”,”_”and” “).now given the current time, please tell us how can it be expressed by the digital clock.
输入
There are several test cases.
Each case contains 4 integers in a line, separated by space.
Proceed to the end of file.
输出
For each test case, output the time expressed by the digital clock such as Sample Output.
示例输入
1 2 5 6
2 3 4 2
示例输出
    _  _  _
  | _||_ |_
  ||_  _||_|
 _  _     _
 _| _||_| _|
|_  _|  ||_
由于我的英语实在是太那个了,so,我是由样例猜出题目的大概意思。当时觉得这个题目挺简单的,然后就直接写代码,结果悲剧发生了,此处省略N个汉字,其实原因就在于在打印的时候,光标不能实现往回走,所以不要妄想一个一个的打印!!!(在Linux中玩过控制台版的数独游戏,说不定真的有这个一个函数可以让光标往回走)
去年10月份,提交了代码,结果AC了,但不是很满意。今天忽然想到这个题目,竟然不晓得自己当初是怎么做出来的,然后就翻阅自己以前提交的代码的记录,... ...,被吓到了,代码居然有90+行。实在是看不下去了,然后就开始修改,万万想不到的是,修改后的代码综合质量比以前的还差(原本排第5位,现在第6位)。
代码:

#include <iostream>
#include <cstdio>
using namespace std;

int main(void)
{
    char zero[10]={' ','_',' ',  '|',' ','|',  '|','_','|'};
    char  one[10]={' ',' ',' ',  ' ',' ','|',  ' ',' ','|'};
    char  two[10]={' ','_',' ',  ' ','_','|',  '|','_',' '};
    char thre[10]={' ','_',' ',  ' ','_','|',  ' ','_','|'};
    char four[10]={' ',' ',' ',  '|','_','|',  ' ',' ','|'};
    char five[10]={' ','_',' ',  '|','_',' ',  ' ','_','|'};
    char  six[10]={' ','_',' ',  '|','_',' ',  '|','_','|'};
    char seve[10]={' ','_',' ',  ' ',' ','|',  ' ',' ','|'};
    char eigh[10]={' ','_',' ',  '|','_','|',  '|','_','|'};
    char nine[10]={' ','_',' ',  '|','_','|',  ' ','_','|'};

    char input[8],*A[4];//用来指向4个数字
    while(gets(input)!=NULL)
    {
        input[1] = input[2];
        input[2] = input[4];
        input[3] = input[6];
        for(int i=0; i<4; i++)//提取4个数字,同时让4个指针分别指向他们
           switch (input[i]-'0')//让这个4个指针,明白要指向谁
           {
               case 0:A[i] = zero;break;
               case 1:A[i] = one ;break;
               case 2:A[i] = two ;break;
               case 3:A[i] = thre;break;
               case 4:A[i] = four;break;
               case 5:A[i] = five;break;
               case 6:A[i] = six ;break;
               case 7:A[i] = seve;break;
               case 8:A[i] = eigh;break;
               case 9:A[i] = nine;break;
           }
        for(int i=0; i<3; i++)//一个数字的图案有3行。
        {
           for(int j=0; j<4; j++)//最终的图案是由4个数字的图案分别组成。
              for(int k=0; k<3; k++)//一个数字的图案其每行是由3个字符构成。
                 cout<<*A[j]++;
           cout<<endl;//打印完一行,就另起一行。
        }
    }
    return 0;
}
/**************************************
    Problem id    : SDUT OJ 2272
    User name     : 李俊
    Result        : Accepted
    Take Memory   : 428K
    Take Time     : 0MS
    Submit Time   : 2014-02-09 18:25:07 
**************************************/

抱歉!评论已关闭.