南邮 OJ 1533 C ? Binary Clock
2015-08-06 09:05
253 查看
C ? Binary Clock
时间限制(普通/Java) : 1000 MS/ 3000 MS 运行内存限制 : 65536 KByte总提交 : 20 测试通过 : 17
比赛描述
A binary clock is a clock which displays traditional sexagesimal time (military format) in a binaryformat.
The most common binary clock uses three columns or three rows of LEDs to represent zerosand 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), witheach
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 LEDrepresents, and then reads the time from left to right. The first column represents
the hour, the nextcolumn 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 eachcolumn 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, andthen reads the time from top to bottom. The top row represents the hour, the next row represents
theminute, and the bottom row represents the second.
![](http://acm.njupt.edu.cn/acmhome/judge/ueditor/jsp/upload/1424581440953.png)
For this problem you will read a time in sexagesimal time format, and output both the vertical andhorizontal binary clock values. The output will be formed
by concatenating together the bits in eachcolumn (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 thatfollow. 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 setnumber
as a decimal integer (start counting at one), a space, the binary time in vertical format (18binary 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
提示
undefined
题目来源
ACM ICPC Greater New York Region 2008
#include<stdio.h> int main(){ int n,ca,i,j,hour,min,sec,a[6][3]; char c[10]; scanf("%d",&n); for(ca=1; ca<=n; ca++){ scanf("%s",c); hour = (c[0]-'0')*10 + c[1] - '0'; min = (c[3]-'0')*10 + c[4] - '0'; sec = (c[6]-'0')*10 + c[7] - '0'; for(i=32,j=0; i; i>>=1,j++){ a[j][0] = hour&i ? 1 : 0; a[j][1] = min&i ? 1 : 0; a[j][2] = sec&i ? 1 : 0; } printf("%d ",ca); for(i=0;i<6;i++){ for(j=0;j<3;j++){ printf("%d",a[i][j]); } } printf(" "); for(j=0;j<3;j++){ for(i=0;i<6;i++){ printf("%d",a[i][j]); } } printf("\n"); } }
相关文章推荐
- eclipse加载工程中出现红叹号
- day12
- git详细介绍
- UI06_ScrollviewLoop
- linux 批量查找替换文件中的某个字符串
- [autoLayout]自动布局下的纯storyboard添加约束--四个imageView平分一个屏幕的宽度
- Java利用Zxing生成二维码
- C++ 强制类型转换
- 南邮 OJ 1532 B ? Cryptoquote
- 20150806
- 翻转排序
- js实现多图片上传
- regsvr32注册模块c\program 加载失败
- 获取设备当前语言设置
- PHP常用的排序和查找算法
- vim编辑器相关介绍 (比较全)
- 基础总结篇之一:Activity生命周期
- 循环滚动
- 南邮 OJ 1531 A ? Sixth Grade Math
- How to Get Insights?