zoukankan      html  css  js  c++  java
  • 时钟输出问题

    问题:

    样例输入

    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(" ");  
        }  
     
        return 0;  
  • 相关阅读:
    【Git】Git 学习笔记(一)
    【工程 Shell】Shell 学习(一)
    Vue 使用 Antd 简单实现左侧菜单栏和面包屑功能
    GoF的23种设计模式的功能
    ASP 对数据库的操作
    注册表修改USB状态(开与关)
    EXE文件关联修复
    CentOS8安装Docker
    GoogleEarth无法连接服务器解决方法
    【转】Qt 实现的拷贝 文件/文件夹 的函数
  • 原文地址:https://www.cnblogs.com/benchao/p/4480854.html
Copyright © 2011-2022 走看看