Time To Get Up
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 478 Accepted Submission(s): 382
Problem Description
Little Q's clock is alarming! It's time to get up now! However, after reading the time on the clock, Little Q lies down and starts sleeping again. Well, he has
5
alarms, and it's just the first one, he can continue sleeping for a while.
Little Q's clock uses a standard 7-segment LCD display for all digits, plus two small segments for the '':'', and shows all times in a 24-hour format. The '':'' segments are on at all times.
Little Q's clock uses a standard 7-segment LCD display for all digits, plus two small segments for the '':'', and shows all times in a 24-hour format. The '':'' segments are on at all times.
Your job is to help Little Q read the time shown on his clock.
Input
The first line of the input contains an integer
T(1≤T≤1440)
, denoting the number of test cases.
In each test case, there is an 7×21 ASCII image of the clock screen.
All digit segments are represented by two characters, and each colon segment is represented by one character. The character ''X'' indicates a segment that is on while ''.'' indicates anything else. See the sample input for details.
In each test case, there is an 7×21 ASCII image of the clock screen.
All digit segments are represented by two characters, and each colon segment is represented by one character. The character ''X'' indicates a segment that is on while ''.'' indicates anything else. See the sample input for details.
Output
For each test case, print a single line containing a string
t
in the format of
HH:MM
, where
t(00:00≤t≤23:59)
, denoting the time shown on the clock.
Sample Input
1 .XX...XX.....XX...XX. X..X....X......X.X..X X..X....X.X....X.X..X ......XX.....XX...XX. X..X.X....X....X.X..X X..X.X.........X.X..X .XX...XX.....XX...XX.
Sample Output
02:38
解析:看到这题首先想到的就是把时钟模拟出来吧,模拟时钟上数字显示的点数,来判断这个数字是什么。相信大佬们也都是这样想的,我写的代码在杭电上A了,但是。。。在我们学校自己的网站上提交却直接Wa掉了(我也很绝望啊!),至今还未找出错误,暂且先列出来,欢迎大家来吐槽错误。
首先先看一下借(偷偷借的)的大佬的代码。
C++ Code
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
#include
<iostream> #include <cstdio> #include <cstring> using namespace std; const char num[ 10 ][ 7 ][ 5 ] = { ".XX." , "X..X" , "X..X" , "...." , "X..X" , "X..X" , ".XX." , "...." , "...X" , "...X" , "...." , "...X" , "...X" , "...." , ".XX." , "...X" , "...X" , ".XX." , "X..." , "X..." , ".XX." , ".XX." , "...X" , "...X" , ".XX." , "...X" , "...X" , ".XX." , "...." , "X..X" , "X..X" , ".XX." , "...X" , "...X" , "...." , ".XX." , "X..." , "X..." , ".XX." , "...X" , "...X" , ".XX." , ".XX." , "X..." , "X..." , ".XX." , "X..X" , "X..X" , ".XX." , ".XX." , "...X" , "...X" , "...." , "...X" , "...X" , "...." , ".XX." , "X..X" , "X..X" , ".XX." , "X..X" , "X..X" , ".XX." , ".XX." , "X..X" , "X..X" , ".XX." , "...X" , "...X" , ".XX." }; char tm[ 10 ][ 25 ]; char n[ 7 ][ 5 ]; int check() { for ( int i= 0 ; i< 10 ; i++) { bool flag = true ; for ( int j= 0 ; j< 7 ; j++) { if (strcmp(n[j], num[i][j]) != 0 ) { flag = false ; break ; } } if (flag) { return i; } } return - 1 ; } int main() { int t; scanf( "%d" , &t); while (t > 0 ) { t--; for ( int i= 0 ; i< 7 ; i++) scanf( "%s" , tm[i]); int a, b, c, d; for ( int i= 0 ; i< 7 ; i++) { strncpy(n[i],tm[i], 4 ); } a = check(); for ( int i= 0 ; i< 7 ; i++) { strncpy(n[i],tm[i]+ 5 , 4 ); } b = check(); for ( int i= 0 ; i< 7 ; i++) { strncpy(n[i], tm[i]+ 12 , 4 ); } c = check(); for ( int i= 0 ; i< 7 ; i++) { strncpy(n[i], tm[i]+ 17 , 4 ); } d = check(); printf( "%d%d:%d%d\n" , a,b,c,d); } return 0 ; } |
简洁明了;
在这里再厚着脸皮亮一下自己小渣渣的代码:
C++ Code
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
///找到电子时钟的显示规律; #include <iostream> #include <cstdio> using namespace std; int main() { char str[ 7 ][ 21 ]; int o,l; int a[ 4 ]; scanf( "%d" ,&o); getchar(); while (o--) { for ( int i= 0 ;i< 7 ;i++) ///时钟的前两个数字 { for ( int j= 0 ;j< 21 ;j++) { str[i][j]=getchar(); } getchar(); } l= 0 ; for ( int p= 0 ;p< 6 ;p+= 5 ) { if (str[ 3 ][ 1 +p]== '.' ) { if (str[ 6 ][ 1 +p]== 'X' ) { a[l]= 0 ; l++; continue ; } else if (str[ 0 ][ 1 +p]== '.' ) { a[l]= 1 ; l++; continue ; } else { a[l]= 7 ; l++; continue ; } } else if (str[ 4 ][ 3 +p]== '.' ) { a[l]= 2 ; l++; continue ; } else if (str[ 1 ][ 0 +p]== '.' ) { a[l]= 3 ; l++; continue ; } else if (str[ 0 ][ 1 +p]== '.' ) { a[l]= 4 ; l++; continue ; } else if (str[ 1 ][ 3 +p]== '.' ) { if (str[ 4 ][ 0 +p]== '.' ) { a[l]= 5 ; l++; continue ; } else { a[l]= 6 ; l++; continue ; } } else if (str[ 4 ][ 0 +p]== 'X' ) { a[l]= 8 ; l++; continue ; } else { a[l]= 9 ; l++; continue ; } } for ( int p= 12 ;p< 19 ;p+= 5 ) ///时钟的后两个数字 { if (str[ 3 ][ 1 +p]== '.' ) { if (str[ 6 ][ 1 +p]== 'X' ) { a[l]= 0 ; l++; continue ; } else if (str[ 0 ][ 1 +p]== '.' ) { a[l]= 1 ; l++; continue ; } else { a[l]= 7 ; l++; continue ; } } else if (str[ 4 ][ 3 +p]== '.' ) { a[l]= 2 ; l++; continue ; } else if (str[ 1 ][ 0 +p]== '.' ) { a[l]= 3 ; l++; continue ; } else if (str[ 0 ][ 1 +p]== '.' ) { a[l]= 4 ; l++; continue ; } else if (str[ 1 ][ 3 +p]== '.' ) { if (str[ 4 ][ 0 +p]== '.' ) { a[l]= 5 ; l++; continue ; } else { a[l]= 6 ; l++; continue ; } } else if (str[ 4 ][ 0 +p]== 'X' ) { a[l]= 8 ; l++; continue ; } else { a[l]= 9 ; l++; continue ; } } printf( "%d%d:%d%d\n" ,a[ 0 ],a[ 1 ],a[ 2 ],a[ 3 ]); } return 0 ; } |
过程看起来比较繁琐,但是。。也确实是有那么一点麻烦,但是真正写的倒是不多,通过每一个数字或几个数字在时钟上的显示点不同来判断数字,上下有分了两个部分(前两个数字和后两个数字,后两个数字直接复制前面的改一下起始位置即可),自我感觉还是比较好理解的;应该还有一些错误我没有考虑到的欢迎吐槽。