1625. Binary Clock
Constraints
Time Limit: 1 secs, Memory Limit: 32 MB
Description
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 <tex2html_verbatim_mark>), with each row above representing higher powers of two, up to 25 <tex2html_verbatim_mark>(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<tex2html_verbatim_mark>), with each column left representing higher powers of two, up to 25 <tex2html_verbatim_mark>(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 e 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.
For example, 10:37:49 would be written vertically as 011001100010100011 and horizontally as 001010100101110001.
Input
The first line of input contains a single integer N <tex2html_verbatim_mark>, (1≤N≤1000) <tex2html_verbatim_mark>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.
Output
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).
Sample Input
2 10:37:49 00:00:01
Sample Output
1 011001100010100011 001010100101110001 2 000000000000000001 000000000000000001
题目分析:水题,不解释。
代码参考:
#include <iostream> #include <cctype> #include <cstring> #include <cmath> #include <vector> using namespace std; int main() { int t; cin >> t; //char s[50]; for (int i = 1; i <= t; ++ i) { int hours, mins, secs; char a; cin >> hours >> a; cin >> mins >> a; cin >> secs; vector<int> v1; vector<int> v2; vector<int> v3; vector<int> v; for (int j = 5; j >= 0; -- j) { if (hours >= pow(2.0, j)) { v1.push_back(1); hours = hours - pow(2.0, j); } else { v1.push_back(0); } if (mins >= pow(2.0, j)) { v2.push_back(1); mins = mins - pow(2.0, j); } else { v2.push_back(0); } if (secs >= pow(2.0, j)) { v3.push_back(1); secs = secs - pow(2.0, j); } else { v3.push_back(0); } } int length = v1.size(); cout << i << " "; for (int k = 0; k < length; ++ k) { cout << v1[k] << v2[k] << v3[k]; } cout << " "; for (int k = 0; k < length; ++ k) { cout << v1[k]; } for (int k = 0; k < length; ++ k) { cout << v2[k]; } for (int k = 0; k < length; ++ k) { cout << v3[k]; } cout << endl; } }
相关推荐
sicily 1562_LVM.cpp参考代码
中山大学 ACM sicily 1294 题目代码
sicily 1274的AC源码,通过且速度快,适合学生使用
本程序解决了Sicily平台上Queue的问题,有较好的可读性
这是C++解题常用的模板,对参加C++机试有较大帮助
本程序是中山大学sicily-1137-1145-1146-1147-1154-1157-1194的代码
西西里全部练习输入输出以及标准程序 超高精度浮点数的输出问题 关联数组
1005. 有向图边的分类 12图算法例题1000. sicily 1155. Can I Post the letteTime Limit: 1sec Mem
sicily 1817和1818的程序,各有两种方法,供参考。
本程序是中山大学sicily 1004-1007-1010-1014-1021 参考代码
本程序是中山大学sicily上1200-1221-1298-1324-1325的参考代码。
包括 sicily online judge 1149等部分题目,线性表,最小生成树,中缀转后缀并计算后缀表达式等。
sicily部分源代码,全都亲测,可通过
中大sicily online judge的刷题指南,里面介绍得很详细,不过,最近sicily好像不能外网访问了。
sicily(soj) 1022 1064 1310 1740 1876 1934 六题的源代码(数据结构综合应用题)
本cpp是sicily的1006的解题代码 这份代码以最简单的方式实现了它的功能要求 值得学习一番
112页的大礼包,sicily的部分ac代码。
Sicily的题目分类:各种题目的分类,大致方法,以及题目难度规范
sicily1007题答案,附代码解释,可以在平台上通过