hrbust 1055 Single【暴力预处理】

来源:互联网 发布:powershell for linux 编辑:程序博客网 时间:2024/05/23 00:05

SingleTime Limit: 1000 MSMemory Limit: 65536 KTotal Submit: 96(28 users)Total Accepted: 29(21 users)Rating: Special Judge: NoDescription

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 Input3
00:00:00
00:00:01
00:00:02Sample Output0
1
1Authorsanpin

题目大意:

给你一个时间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]);    }}






0 0