【CodeForces - 260B 】Ancient Prophesy (暴力匹配,BF算法,日期字符串)

题干:

A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-".

We'll say that some date is mentioned in the Prophesy if there is a substring in the Prophesy that is the date's record in the format "dd-mm-yyyy". We'll say that the number of the date's occurrences is the number of such substrings in the Prophesy. For example, the Prophesy "0012-10-2012-10-2012" mentions date 12-10-2012 twice (first time as "0012-10-2012-10-2012", second time as "0012-10-2012-10-2012").

The date of the Apocalypse is such correct date that the number of times it is mentioned in the Prophesy is strictly larger than that of any other correct date.

A date is correct if the year lies in the range from 2013 to 2015, the month is from 1 to 12, and the number of the day is strictly more than a zero and doesn't exceed the number of days in the current month. Note that a date is written in the format "dd-mm-yyyy", that means that leading zeroes may be added to the numbers of the months or days if needed. In other words, date "1-1-2013" isn't recorded in the format "dd-mm-yyyy", and date "01-01-2013" is recorded in it.

Notice, that any year between 2013 and 2015 is not a leap year.

Input

The first line contains the Prophesy: a non-empty string that only consists of digits and characters "-". The length of the Prophesy doesn't exceed 105 characters.

Output

In a single line print the date of the Apocalypse. It is guaranteed that such date exists and is unique.

Examples

Input

777-444---21-12-2013-12-2013-12-2013---444-777

Output

13-12-2013

题目大意:

有一个字符串,让你找出其中最多的合法日期出现次数,格式为:dd-mm-yyyy。

解题报告:

  学会了KMP,自然会接触到BF算法吧。。不难想到这题的数据量肯定是要暴力的。于是乎又到了考验代码仔细度的时候了。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e5 + 5;
char s[MAX];
char tmp[15];
string ans;
int month[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
map<string,int> mp;
map<string,int> :: iterator it;
int main()
{cin>>s;int len = strlen(s);for(int i = 0; i<=len-10; i++) {for(int j = 0; j<10; j++) {tmp[j] = s[j+i];}tmp[10]='\0';if(tmp[6] != '2' || tmp[7] != '0' || tmp[8] != '1') continue;if(tmp[9] != '3' && tmp[9] != '4' && tmp[9] != '5') continue;//处理年份 if(tmp[2] != '-' || tmp[5] != '-') continue;if(!isdigit(tmp[0]) || !isdigit(tmp[1]) || !isdigit(tmp[3]) || !isdigit(tmp[4]) || !isdigit(tmp[6]) || !isdigit(tmp[7]) || !isdigit(tmp[8]) || !isdigit(tmp[9])) continue;int yue = (tmp[3]-'0')*10+tmp[4]-'0';if(yue <=0 || yue > 12) continue;int day = (tmp[0]-'0')*10 + tmp[1]-'0';if(day > month[yue] || day <= 0)  continue;mp[tmp]++;}it = mp.begin();int maxx = 0;for(;it!=mp.end(); ++it) {if(maxx < (it->second)) {maxx = it->second;ans= it->first;}}cout << ans << endl;return 0 ;}

总结:

  刚开始1WA发现那个if(day > month[yue] || day <= 0)  continue;写成了day<0,,改过来交一发还是WA,想想可能是因为‘-’字符没有判断正确,于是直接把所有的都判断一遍。,再交AC了。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441204.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

github 上传代码_leetcode爬虫:爬取代码;生成readme;上传github

Leetcode-Helper哪个程序员 不想一键下写过的代码&#xff0c;自动上传Github&#xff0c;并且还能生成好看的README呢&#xff1f;有用的话点个⭐吧&#xff0c;谢谢你。Leetcode-Helper传送门​github.com主要功能 模拟登陆力扣中国站(leetcode-cn)爬取每题提交的ac代码&…

绝地求生信号枪只能在服务器吗,绝地求生信号枪怎么用?信号枪刷新点及用法详解...

绝地求生信号枪怎么用&#xff1f;信号枪刷新点及用法详解2018-03-15 15:22:12来源&#xff1a;吃鸡小助手编辑&#xff1a;野狐禅评论(0)绝地求生近日更新中悄悄加入了信号枪&#xff0c;引得广大玩家热情满满的在游戏中寻找&#xff0c;信号枪到底怎么用呢&#xff1f;下面就…

spring的beanutils工具类_基于spring-beans实现工具类BeanUtils基于Class实例化注入对象及查找方法、复制属性等操作...

一、前言基于spring-beans(4.1.4)的工具类org.springframework.beans.BeanUtils对注入spring对象按照Class实例化instantiateClass、class对象方法名称methodName查找findMethod、属性查找对于class类信息findPropertyType、对象属性复制copyProperties等常用操作&#xff0c;具…

【CodeForces - 260C】Balls and Boxes (思维模拟,有坑,时光倒流)

题干&#xff1a; Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right. Once Vasya chose one of the boxes, lets assume that its number is i, took all balls out from it (it …

文件服务器共享文件夹访问权限,5对文件服务器中的共享文件夹进行访问权限控制...

对文件服务器中的共享文件夹进行访问权限控制1. 实训目的在Windows Server 2003环境下设置文件服务器的目的是要对多用户进行资源共享&#xff0c;这其中经常遇到不同用户应该分配不同权限的问题&#xff0c;通过这个实训希望读者了解Windows Server 2003中访问权限设置方法和具…

java生日正则表达式_java之正则表达式、日期操作

正则表达式和日期操作正则表达式简介正则表达式就是使用一系列预定义的特殊字符来描述一个字符串的格式规则&#xff0c;然后使用该格式规则匹配某个字符串是否符合格式要求。作用:比如注册邮箱,邮箱有用户名和密码,一般会对其限制长度,这个限制长度的事情就是正则表达式做的规…

渲染服务器位置,如何用服务器做渲染

如何用服务器做渲染 内容精选换一换&#xfffd;&#xfffd;&#xfffd;&#xfffd;BoostKit ARMԭ&#xfffd;&#xfffd;ʹ&#xfffd;&#xfffd;&#xfffd;׼&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;嵥&#xfffd;&#xfffd…

【HDU - 2376】Average distance (树,平均距离,算贡献)

题干&#xff1a; Given a tree, calculate the average distance between two vertices in the tree. For example, the average distance between two vertices in the following tree is (d 01 d 02 d 03 d 04 d 12 d 13 d 14 d 23 d 24 d 34)/10 (63799131510122)/10…

读取ppt并存入数据库_Java解析Excel文件并把数据存入数据库

前段时间做一个小项目&#xff0c;为了同时存储多条数据&#xff0c;其中有一个功能是解析Excel并把其中的数据存入对应数据库中。花了两天时间&#xff0c;不过一天多是因为用了"upload"关键字作为URL从而导致总报同一个错&#xff0c;最后在同学的帮助下顺利解决&a…

两台虚拟服务器如何级联,[教程] 利用open vswitch建立vxlan隧道实现不同主机上的虚拟交换机级联...

写在开头在某些环境下&#xff0c;需要实现两台物理机中的openvswitch交换机级联&#xff0c;以实现两台交换机中的设备互相通讯&#xff0c;这里使用vxlan隧道技术&#xff0c;将数据包封装在UDP中&#xff0c;通过以太网实现数据包传输。VXLAN是一种大二层的虚拟技术&#xf…

【POJ - 3041】Asteroids (二分图,最小点覆盖)

题干&#xff1a; Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N grid (1 < N < 500). The grid contains K asteroids (1 < K < 10,000), which are conveniently located at the lattice points of the…

华为虚拟服务器lanip地址,2018软考网络工程师《华为基础实验》十九配置路由器为DHCPServer...

原标题&#xff1a;2018软考网络工程师《华为基础实验》十九配置路由器为DHCPServer实验要求:在R1上使能DHCP 功能。创建三个全局地址池&#xff0c;用于为三个不同部门的PC分配IP 地址。配置地址池的相关属性。在R1的接口下配置基于全局地址池的服务方式&#xff0c;实现DHCP …

电脑重启bootmgr_电脑系统启动:显示0xc0000428怎么办

错误代码&#xff1a;0xc0000428 一般都是驱动问题&#xff0c;只需要找到报错的路径驱动程序&#xff0c;删除再重启就基本上可以解决了。制作一个U盘启动&#xff0c;进入PE&#xff0c;然后删除”\Windoiws\System32\drivers\DsArk64.sys“文件&#xff0c;再重启就可以了。…

【 POJ - 2033 】Alphacode (dp,有坑)

题干&#xff1a; Alice and Bob need to send secret messages to each other and are discussing ways to encode their messages: Alice: "Lets just use a very simple code: Well assign A the code word 1, B will be 2, and so on down to Z being assigned 26.&…

两组的数据平均值合并_不要进入数据陷进

学习统计让我们不再被一些数据迷惑进入数据陷进&#xff08;例如平均工资&#xff09;从而做出正确的决策。描述性统计分析包括数据的分布、集中、波动的测度指标。平均值&#xff1a;一组数据的加和除以数据的个数&#xff08;容易随极端值变化&#xff09; 中位数&#xff1a…

【POJ - 3342】Party at Hali-Bula(树形dp,最大独立集,是否有唯一解)

题干&#xff1a; Dear Contestant, Im going to have a party at my villa at Hali-Bula to celebrate my retirement from BCM. I wish I could invite all my co-workers, but imagine how an employee can enjoy a party when he finds his boss among the guests! So, I…

安川西格玛7驱动器手册_什么是伺服驱动器?选型的原则有哪些?

头条号私信回复1&#xff0c;获取海量免费学习资源&#xff0c;内容包括自动化电气工程师必备的软件、电子书、视频教程等题图&#xff1a;伺服驱动器来源&#xff1a;百度图片什么是伺服驱动器&#xff1f;该如何选型&#xff1f;有哪些主流品牌&#xff1f;你想知道的全在这里…

java猜数游戏图形界面_Java做一个猜数的小游戏

Author &#xff1a; By Runsen效果展现猜数字游戏是一个简单&#xff0c;有趣的小游戏。游戏者通过输入一个指定区间的数字&#xff0c;与系统产生的随机数进行对比&#xff0c;然后输出相应的结果。游戏运行时产生一个0&#xff0d;10之间的随机整数&#xff0c;要求用户从控…

【CodeForces - 266C】Below the Diagonal (递归,子问题,贪心模拟)

题干&#xff1a; You are given a square matrix consisting of n rows and n columns. We assume that the rows are numbered from 1 to n from top to bottom and the columns are numbered from 1to n from left to right. Some cells (n - 1 cells in total) of the t…

python 0o_Python 中的比较:is 与 ==

在 Python 中会用到对象之间比较&#xff0c;可以用 &#xff0c;也可以用 is 。但是它们的区别是什么呢&#xff1f;is 比较的是两个实例对象是不是完全相同&#xff0c;它们是不是同一个对象&#xff0c;占用的内存地址是否相同。莱布尼茨说过&#xff1a;“世界上没有两片完…