hrbust 1055 Single【暴力预处理】

Single
Time Limit: 1000 MSMemory Limit: 65536 K
Total Submit: 96(28 users)Total Accepted: 29(21 users)Rating: Special Judge: No
Description

There are many handsome single boys in our team, for example, me. Some times, we like count singles. For example, in the famous “November 11th” (11.11), there are four singles ,so, single is actually 1. For another example, there are 2 singles in the time “1:01”.  We are all boring guys, and here is an boring problem. Time is in the format HH:MM:SS; one day starts from 00:00:00, and ends at 24:00:00, we just want to know how many singles has passed till a certain time (included)

Input

First line is the number of cases: n, the next n lines are each a time, exactly in the format described above. It's guaranteed that the time is in the right range (00:00:00 ~ 24:00:00)

Output

For each case, just give us the answer in a single line, no extra character is needed.

Sample Input
3
00:00:00
00:00:01
00:00:02
Sample Output
0
1
1
Author
sanpin

题目大意:

给你一个时间t,让你计算从00:00:00到当前时间(包括当前时间这一秒)一共出现了多少次数字1.


思路:


直接暴力预处理从00:00:00到24:00:00之间这些时刻都出现了多少个1,对应存到数组ans【24*60*60】中即可,对应假设当前时间为:a:b:c,那么此时的答案我们记录到数组ans【a*60*60+b*60+c】中。

那么对应输入a:b:c的时候,直接输出ans【a*60*60+b*60+c】即可。


Ac代码:

#include<stdio.h>
#include<string.h>
using namespace std;
int ans[24*60*60*10];
int cal(int num)
{
    int sum=0;
    while(num)
    {
        if(num%10==1)sum++;
        num/=10;
    }
    return sum;
}
void init()
{
    int output=0;
    int a=0,b=0,c=0;
    while(1)
    {
        output+=cal(a);
        output+=cal(b);
        output+=cal(c);
        ans[a*60*60+b*60+c]=output;
        c++;
        if(c==60)
        {
            c=0;
            b++;
            if(b==60)
            {
                b=0;
                a++;
                if(a==24)break;
            }
        }
    }
}
int main()
{
    init();
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int a,b,c;
        scanf("%d:%d:%d",&a,&b,&c);
        int tmp=a*60*60+b*60+c;
        printf("%d\n",ans[tmp]);
    }
}






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值