码迷,mamicode.com
首页 > 其他好文 > 详细

NBUT 1219 Time

时间:2015-08-18 16:27:05      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:字符串   模拟   

  • [1219] Time

  • 时间限制: 1000 ms 内存限制: 131072 K
  • 问题描述
  • 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
  • 样例输出
  •     _  _  _ 
      | _||_ |_ 
      ||_  _||_|
     _  _     _ 
     _| _||_| _|
    |_  _|  ||_ 
  • 提示
  • The digits showed by the digital clock are as follows:
       _  _     _  _  _  _  _  _ 
     | _| _||_||_ |_   ||_||_|| |
     ||_  _|  | _||_|  ||_| _||_|
  • 来源
  • 辽宁省赛2010

    题目意思也很简单就是用字符串模拟时钟,注意每个数字占三格,最暴力的方法就是直接定义三个字符数组,按要求输出,还有一点就是0在最后一位,要特殊处理一下。

    #include <algorithm>
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <cstdio>
    #include <string>
    #include <vector>
    #include <cmath>
    #include <ctime>
    #include <queue>
    #include <stack>
    #include <set>
    #include <map>
    using namespace std;
    typedef long long LL;
    const int maxn= 100000 + 10;
    
    char s1[35]="     _  _     _  _  _  _  _  _ ";
    char s2[35]="   | _| _||_||_ |_   ||_||_|| |";
    char s3[35]="   ||_  _|  | _||_|  ||_| _||_|";
    int main() {
        int a,b,c,d;
        while(~scanf("%d%d%d%d",&a,&b,&c,&d))
        {
            getchar();
            if(a==0)
                a=10;
            if(b==0)
                b=10;
            if(c==0)
                c=10;
            if(d==0)
                d=10;
            printf("%c%c%c%c%c%c%c%c%c%c%c%c\n",s1[a*3-2],s1[a*3-1],s1[a*3],s1[b*3-2],s1[b*3-1],s1[b*3],s1[c*3-2],s1[c*3-1],s1[c*3],s1[d*3-2],s1[d*3-1],s1[d*3]);
            printf("%c%c%c%c%c%c%c%c%c%c%c%c\n",s2[a*3-2],s2[a*3-1],s2[a*3],s2[b*3-2],s2[b*3-1],s2[b*3],s2[c*3-2],s2[c*3-1],s2[c*3],s2[d*3-2],s2[d*3-1],s2[d*3]);
            printf("%c%c%c%c%c%c%c%c%c%c%c%c\n",s3[a*3-2],s3[a*3-1],s3[a*3],s3[b*3-2],s3[b*3-1],s3[b*3],s3[c*3-2],s3[c*3-1],s3[c*3],s3[d*3-2],s3[d*3-1],s3[d*3]);
        }
        return 0;
    }
    

    这是最开始写的纯暴力方法,看上去好不协调啊…+_+…

    #include <algorithm>
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <cstdio>
    #include <string>
    #include <vector>
    #include <cmath>
    #include <ctime>
    #include <queue>
    #include <stack>
    #include <set>
    #include <map>
    using namespace std;
    typedef long long LL;
    const int maxn= 100000 + 10;
    
    char  s[3][35]= {"     _  _     _  _  _  _  _  _ ",
                     "   | _| _||_||_ |_   ||_||_|| |",
                     "   ||_  _|  | _||_|  ||_| _||_|"
                    };
    int a[4];
    int main() {
        while(~scanf("%d",&a[0])) {
            for(int i=1; i<4; i++)
                scanf("%d",&a[i]);
            for(int i=0; i<4; i++)
                if(!a[i])
                    a[i]+=10;
            for(int i=0; i<3; i++) {
                for(int j=0; j<4; j++)
                {
                    int t=a[j];
                    printf("%c%c%c",s[i][t*3-2],s[i][t*3-1],s[i][t*3]);
                }
                puts("");
            }
        }
        return 0;
    }
    

    O(∩_∩)O哈哈~这样看上去清爽多了吧。

    还有一种比较屌的方法,是照着基神的代码敲的(真不知道基神脑袋怎么长的,就是跟常人思维不一样……好吧…%>_<%…其实不可否认的还是自己太愚笨…Orz),虽然本人目前没看懂,但还是贴上来把,求大神赐教^_^

    #include <algorithm>
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <cstdio>
    #include <string>
    #include <vector>
    #include <cmath>
    #include <ctime>
    #include <queue>
    #include <stack>
    #include <set>
    #include <map>
    using namespace std;
    typedef long long LL;
    const int maxn= 100000 + 10;
    
    char  s[50][50];
    int data[]={119,36,93,109,46,107,123,37,127,111};
    
    int slove(int p,int x)
    {
        x=data[x];
        if(x>>0&1)s[0][p+1]='_';
        if(x>>1&1)s[1][p+0]='|';
        if(x>>2&1)s[1][p+2]='|';
        if(x>>3&1)s[1][p+1]='_';
        if(x>>4&1)s[2][p+0]='|';
        if(x>>5&1)s[2][p+2]='|';
        if(x>>6&1)s[2][p+1]='_';
    }
    
    int main() {
        int a[5];
        while(~scanf("%d",&a[0])) {
            for(int i=1; i<4; i++)
                scanf("%d",&a[i]);
            memset(s,' ',sizeof(s));
            for(int i=0;i<3;i++)
                s[i][12]=0;
            for(int i=0;i<4;i++)
                slove(i*3,a[i]);
            for(int i=0;i<3;i++)
                printf("%s\n",s[i]);
        }
        return 0;
    }
    

版权声明:本文为博主原创文章,未经博主允许不得转载。

NBUT 1219 Time

标签:字符串   模拟   

原文地址:http://blog.csdn.net/zhang_xueping/article/details/47751293

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!