HDU6077 2017杭电多校联赛第四场-Time To Get Up

来源:互联网 发布:国外语音聊天软件 编辑:程序博客网 时间:2024/05/16 04:04

题意:给我们一个7*21的字符串,由LED灯显示数字,让我们根据显示的数字输出时间。
思路:我们可以每五列的显示看作一个数字,第十一列就是时钟里的“:”号,不需要考虑,将0~9的数字按照LED灯的方式写出来,会发现数字1的“X”的数量有4个,数字7的“X”的数量有6个,数字4的“X”的数量有8个,数字8的“X”的数量有14个,他们都是唯一的,而数字2、3、5的“X”的数量有10个,数字0、6、9的“X”的数量有12个。所以现在只需要特判数量是10和12 的就可以了,看代码。

#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>using namespace std;char str[10][25];int T;int ans,cnt;int Solve(int x,int y){    ans=0;    for(int i=0;i<7;i++)    {        for(int j=x;j<y;j++)        {            if(str[i][j]=='X')               ans++;        }    }    if(ans==4) cnt=1;    if(ans==6) cnt=7;    if(ans==8) cnt=4;    if(ans==14) cnt=8;    if(ans==10)    {        if(str[1][x]=='X'||str[1][x+1]=='X') cnt=5;        else if(str[4][x]=='X'||str[4][x+1]=='X') cnt=2;           else cnt=3;    }//因为在LED中数字最多占了四列,而我们考虑的是五列,所以这里对2、3、5特判时用了或的关系,这里需要注意下,下面的ans=12也是同样的道理    if(ans==12)     {        if(str[3][x+2]=='X'||str[3][x+1]=='X')        {            if(str[1][y-1]=='X'||str[1][y-2]=='X') cnt=9;            else cnt=6;        }        else cnt=0;    }   return cnt;  }int main(){    int a,b,c,d;    while(~scanf("%d",&T))    {        for(int i=0;i<7;i++)          scanf("%s",str[i]);        a=Solve(0,5);        b=Solve(5,10);        c=Solve(11,16);//因为第11列是时钟里的“:”号,所以这里从第12列开始处理        d=Solve(16,21);        printf("%d%d:%d%d\n",a,b,c,d);      }    return 0;}

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

原创粉丝点击