Codeforces 16D Logging Problem Solution
subject
meaning of the title
Calculate the minimum number of days between logs according to the logs. Only 10 records can be generated in one minute.
Code
#include <bits/stdc++.h> using namespace std; int ctoi (char x) { return x-'0'; } int main() { char str[100][200]; vector<int> str24; int n,temp; cin>>n; getchar(); for (int tmp=0;tmp<n;tmp++) { gets(str[tmp]); temp=0; if (str[tmp][7]=='a') { if (str[tmp][1]=='1'&&str[tmp][2]=='2') temp+=ctoi(str[tmp][4])*10+ctoi(str[tmp][5]); else temp+=ctoi(str[tmp][1])*10*60+ctoi(str[tmp][2])*60+ctoi(str[tmp][4])*10+ctoi(str[tmp][5]); } else{ if (str[tmp][1]=='1'&&str[tmp][2]=='2') temp+=12*60+ctoi(str[tmp][4])*10+ctoi(str[tmp][5]); else temp+=12*60+ctoi(str[tmp][1])*10*60+ctoi(str[tmp][2])*60+ctoi(str[tmp][4])*10+ctoi(str[tmp][5]); } str24.push_back(temp); } int day=1,count=1,def=str24[0]; for (int i=1;i<n;i++) { if (str24[i]==def) { count++; } else if (str24[i]<def) { count=1; day++; } else count=1; if (count>10) { count=1; day++; } def=str24[i]; } cout<<day; return 0; }
thinking
First of all, turn all log time into minutes, then enter the cycle comparison, and compare this time with the previous one. If the result is less than 0, add one day to the counter, equal to zero, add one day to the counter. When the counter is full of 10 days, pay attention to 12:00 am in the morning, the counter and the number of days should be 1 at the beginning. The counter is used to record the number of times a value appears; the number of log days is at least 1).
summary
This question 2000 points, pay attention to consider three points: after 12 a.m. calculate a new day (excluding 12 points); how to count the counter; to convert the 12-hour system into minutes to facilitate comparison. This topic is clear and simple.