17暑假多校联赛4.11 HDU 6077 Time To Get Up

Time To Get Up

Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 524288/524288 K (Java/Others)

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.
这里写图片描述
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


题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=6077

分析

题意:当时没翻译题目,直接看到了图片还有样例输入输出,就明白是给出矩阵,输出矩阵显示的时间
因为他的输入都是7x21的矩阵,所以每个数的位置是固定的,只用推出是哪个数即可
根据中心两点是否为X可以分为两堆,再根据左上,右上,左下,右下将各个数分辨出来,这种方法直接将4个位置一起考虑,可以直接写一个函数调用4次就行了
因为是时间第一个位置只能为0,1,2,第三个位置只能为0,1,2,3,4,5,6,所以也可以少几次判断
也可以直接将每个数的点给列出,判断满足哪个数的情况就输出谁,不过这样会使代码很长很乱

代码

#include 
using namespace std;
char alarm[8][22];
int change(int x)
{
    if(alarm[3][x]=='X')
    {
        if(alarm[2][x-1]=='.')
        {
            if(alarm[4][x-1]=='.')return(3);
            return(2);
        }
        if(alarm[2][x+2]=='.')
        {
            if(alarm[4][x-1]=='.')return(5);
            return(6);
        }
        if(alarm[4][x-1]=='.')
        {
            if(alarm[6][x]=='.')return(4);
            return(9);
        }
        return(8);
    }
    if(alarm[6][x]=='.')
    {
        if(alarm[0][x]=='.')return(1);
        return(7);
    }
    return(0);
}
int main()
{
    int T;
    scanf("%d",&T);
    getchar();
    while(T--)
    {
        for(int i=0; i<7; i++)
        {
            for(int j=0; j<21; j++)scanf("%c",&alarm[i][j]);
            getchar();
        }
        printf("%d%d:%d%d\n",change(1),change(6),change(13),change(18));
    }
}

你可能感兴趣的:(Freshman丶字符串,Freshman丶比赛,Freshman丶HDU)