TZU2014年省赛个人热身赛1 1962:Binary Clock

描述

A binary clock is a clock which displays traditional sexagesimal time (military format) in a binary format. The most common binary clock uses three columns or three rows of LEDs to represent zeros and ones. Each column (or row) represents a time-unit value.

When three columns are used (vertically), the bottom row in each column represents 1 (or 20 ), with each row above representing higher powers of two, up to 25 (or 32). To read each individual unit (hours, minutes or seconds) in the time, the user adds the values that each illuminated LED represents, and then reads the time from left to right. The first column represents the hour, the next column represents the minute, and the last column represents the second.

When three rows are used (horizontally), the right column in each row represents 1 (or 20 ), with each column left representing higher powers of two, up to 25 (or 32). To read each individual unit (hours, minutes or seconds) in the time, the user adds the values that each illuminated LED represents, and then reads the time from top to bottom. The top row represents the hour, the next row represents the minute, and the bottom row represents the second.

For example:

For this problem you will read a time in sexagesimal time format, and output both the vertical and horizontal binary clock values. The output will be formed by concatenating together the bits in each column (or row) to form two 18 character strings of 1's and 0's as shown below.

10:37:49 would be written vertically as 011001100010100011 and horizontally as 001010100101110001.

输入

The first line of input contains a single integer N, (1 ≤ N ≤ 1000) which is the number of data sets that follow. Each data set consists of a single line of input containing the time in sexagesimal format.

输出

For each data set, you should generate one line of output with the following values: The data set number as a decimal integer (start counting at one), a space, the binary time in vertical format (18 binary digits), a space and the binary time in horizontal format (18 binary digits).

样例输入

2
10:37:49
00:00:01

样例输出

1 011001100010100011 001010100101110001 
2 000000000000000001 000000000000000001
 
题意:将时间按照题意竖向和横向输出
 
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int main()
{
    int h,m,s,t,i,j,cas = 1;
    char c1[10],c2[10],c3[10],r1[10],r2[10],r3[10];
    scanf("%d",&t);
    while(t--)
    {
        memset(c1,'0',sizeof(c1));
        memset(c2,'0',sizeof(c2));
        memset(c3,'0',sizeof(c3));
        scanf("%d:%d:%d",&h,&m,&s);
        i = 0;
        while(h)
        {
            int r = h%2;
            c1[i++] = r+'0';
            h/=2;
        }
        i = 0;
        while(m)
        {
            int r = m%2;
            c2[i++] = r+'0';
            m/=2;
        }
        i = 0;
        while(s)
        {
            int r = s%2;
            c3[i++] = r+'0';
            s/=2;
        }
        printf("%d ",cas++);
        for(i = 5;i>=0;i--)
        printf("%c%c%c",c1[i],c2[i],c3[i]);
        printf(" ");
        for(i = 5;i>=0;i--)
        printf("%c",c1[i]);
        for(i = 5;i>=0;i--)
        printf("%c",c2[i]);
        for(i = 5;i>=0;i--)
        printf("%c",c3[i]);
        printf("\n");
    }

    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值