G - Time To Get Up
HDU-6077
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.
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.
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
题意:给你一个字符串,输出字符串对应的时间
解法:每个数字用一个数组表示,bool类型的a[7],每条边对应一个索引,如果有这条边,值为1,否则为0,两个函数,第一个函数根据字符串构建数组,第二个函数根据数组输出数字
代码:
#include
using namespace std;
char a[7][21];
bool b[4][7];
int c[4];
void op(int x,int y,int z){
if(a[x][y+1]=='X')
b[z][0]=1;
if(a[x+1][y]=='X')
b[z][1]=1;
if(a[x+1][y+3]=='X')
b[z][2]=1;
if(a[x+3][y+1]=='X')
b[z][3]=1;
if(a[x+4][y]=='X')
b[z][4]=1;
if(a[x+4][y+3]=='X')
b[z][5]=1;
if(a[x+6][y+1]=='X')
b[z][6]=1;
}
int main()
{
int n;
cin>>n;
while(n--){
for(int i=0;i<7;i++)
for(int j=0;j<21;j++)
cin>>a[i][j];
for(int i=0;i<4;i++)
for(int j=0;j<7;j++)
b[i][j]=0;
op(0,0,0);
op(0,5,1);
op(0,12,2);
op(0,17,3);
for(int i=0;i<4;i++){
if(b[i][0]==0){
if(b[i][1]==0)
c[i]=1;
else
c[i]=4;
}
else if(b[i][1]==0){
if(b[i][5]==0)
c[i]=2;
else if(b[i][3]==0)
c[i]=7;
else
c[i]=3;
}
else if(b[i][2]==0){
if(b[i][4]==0)
c[i]=5;
else
c[i]=6;
}
else if(b[i][3]==0)
c[i]=0;
else if(b[i][4]==0)
c[i]=9;
else
c[i]=8;
}
cout<