16D

来源:互联网 发布:手机淘宝上的免费开店 编辑:程序博客网 时间:2024/05/16 03:42
D. Logging
time limit per test
1 second
memory limit per test
64 megabytes
input
standard input
output
standard output

The main server of Gomble company received a log of one top-secret process, the name of which can't be revealed. The log was written in the following format: «[date:time]: message», where for each «[date:time]» value existed not more than 10 lines. All the files were encoded in a very complicated manner, and only one programmer — Alex — managed to decode them. The code was so complicated that Alex needed four weeks to decode it. Right after the decoding process was finished, all the files were deleted. But after the files deletion, Alex noticed that he saved the recordings in format «[time]: message». So, information about the dates was lost. However, as the lines were added into the log in chronological order, it's not difficult to say if the recordings could appear during one day or not. It is possible also to find the minimum amount of days during which the log was written.

So, to make up for his mistake Alex has to find the minimum amount of days covered by the log. Note that Alex doesn't have to find the minimum amount of days between the beginning and the end of the logging, he has to find the minimum amount of dates in which records could be done. (See Sample test 2 for further clarifications).

We should remind you that the process made not more than 10 recordings in a minute. Consider that a midnight belongs to coming day.

Input

The first input line contains number n (1 ≤ n ≤ 100). The following n lines contain recordings in format «[time]: message», where time is given in format «hh:mm x.m.». For hhtwo-digit numbers from 01 to 12 are used, for mm two-digit numbers from 00 to 59 are used, and x is either character «a» or character «p». A message is a non-empty sequence of Latin letters and/or spaces, it doesn't start or end with a space. The length of each message doesn't exceed 20.

Output

Output one number — the minimum amount of days covered by the log.

Examples
input
5[05:00 a.m.]: Server is started[05:00 a.m.]: Rescan initialized[01:13 p.m.]: Request processed[01:10 p.m.]: Request processed[11:40 p.m.]: Rescan completed
output
2
input
3[09:00 a.m.]: User logged in[08:00 a.m.]: User logged in[07:00 a.m.]: User logged in
output
3


题意:给你n行字符串是一个公司服务器的登录记录,每一行都有时间记录。让我们输出可能的最小天数。模拟就是。但是很坑。

题解:模拟,但是有两个坑点,一:就是重复的时间算一天的,但是超过10条就是第二天的呢,二:最坑的就是不符合日常生活逻辑,am 12点算的是凌晨。其余和和日常一样。

首先第一个代码是错误的,会wa 26组,我测试二十六组是正确答案4,但是cf上显示的是6,不懂!然后看再看别人博客是相同时间是一个一个加,取末尾数字,判断是否是0,也就是相同记录大于10个的算作另一天。

#include<bits/stdc++.h>using namespace std;int main(){    char s[50];    int x[50];    int n,ans,a,b,cnt;    while(cin>>n)    {        ans=1;        cnt=0;        getchar();        for(int i=0; i<n; i++)        {            gets(s);            a=(s[1]-'0')*10+(s[2]-'0');            b=(s[4]-'0')*10+(s[5]-'0');            if(a==12&&s[7]=='a')///am 12点算作凌晨                a=0;            else if(a!=12&&s[7]=='p')                 a+=12;            x[i]=a*60+b;         ///把每天时间转成分钟            if(x[i]==x[i-1])                cnt++;      ///记录重复条数,后面/10就是看看超过10条的记录                                  ///加在总天数上面        }        for(int i=1; i<n; i++)        {            if(x[i-1]>x[i])                  ans++;        }        cout<<ans+cnt/10<<endl;    }    return 0;}
修改后AC代码:
#include<bits/stdc++.h>using namespace std;int main(){    char s[50];    int x[110],time[110];    int n,ans,a,b,cnt;    while(cin>>n)    {        ans=1;//        cnt=0;        memset(time,0,sizeof(time));        memset(x,0,sizeof(x));        getchar();        for(int i=1; i<=n; i++)        {            gets(s);            a=(s[1]-'0')*10+(s[2]-'0');            b=(s[4]-'0')*10+(s[5]-'0');            if(a==12&&s[7]=='a')///am 12点算作凌晨                a=0;            else if(a!=12&&s[7]=='p')                a+=12;            x[i]=a*60+b;         ///把每天时间转成分钟            if(x[i]==x[i-1])            {                time[i]=time[i-1]+1;                time[i]%=10;            }//           if(x[i]==x[i-1])//               cnt++;      ///记录重复条数,后面/10就是看看超过10条的记录//                                 ///加在总天数上面        }        for(int i=1; i<=n; i++)        {            if(x[i-1]>x[i])                ans++;            else if(x[i]==x[i-1])            {                if(!time[i])                    ans++;            }        }        cout<<ans<<endl;    }    return 0;}


原创粉丝点击