16D
来源:互联网 发布:手机淘宝上的免费开店 编辑:程序博客网 时间:2024/05/16 03:42
题意:给你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;}
阅读全文
0 0
- 16D
- 正则表达式 \d{12}|\d{13}|\d{16}|\d{20}
- 16初出茅庐D题
- CodeForces 16D Logging
- 16D. Logging
- d
- d
- d
- d
- d
- D
- d
- d
- d
- d
- d
- %d
- d
- Dockerfile:mysql镜像编写
- 小菜鸟的第一个爬虫:豆瓣爬取电影信息
- SpringMVC之拦截器
- uva 1225
- mysql进阶
- 16D
- 「 操作系统 」
- 抓包工具的配置
- 【sql】oracle运维sql之event
- Java打包找不到资源文件问题
- 功能
- Web项目中使用Spring 3.x + Quartz 2.x实现作业调度详解
- 面向对象--简单的内部类
- Ciclop开源3D扫描仪软件---Horus源码分析之src\horus\engine\calibration\Pattern.py