CodeForces - 260B Ancient Prophesy

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

我也不太明白为什么我写的代码不对,一直WA在第三个上。

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#define N 200100
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int MAX=2e6+5;
char a[100100];
char c[1000][10];
int d[1000];
int b[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int main(){int l,i,j,m,day,k,flag,maxx,t;while(scanf("%s",a)!=EOF){memset(c,0,sizeof(c));memset(d,0,sizeof(d));k=0;l=strlen(a);for(i=6;i<l-3;i++){if(a[i]=='2'&&a[i+1]=='0'&&a[i+2]=='1'&&a[i+3]>='3'&&a[i+3]<='5'){//              cout<<"flag1"<<endl;
//              cout<<a[i-6]<<" "<<a[i-5]<<" "<<a[i-4]<<" "<<a[i-3]<<" "<<a[i-2]<<" "<<a[i-1]<<endl;if(a[i-1]=='-'&&a[i-4]=='-'&&a[i-2]<='9'&&a[i-2]>='0'&&a[i-3]>='0'&&a[i-3]<='9'&&a[i-5]<='9'&&a[i-5]>='0'&&a[i-6]<='9'&&a[i-6]>='0'){//                  cout<<"flag2"<<endl;m=(a[i-3]-'0')*10+(a[i-2]-'0');day=(a[i-5]-'0')*10+(a[i-4]-'0');if(m>12){continue;}
//                  cout<<m<<" "<<day<<endl;flag=1;if(b[m]>=day){for(j=0;j<k;j++){if(c[j][0]==a[i-6]&&c[j][1]==a[i-5]&&c[j][2]==a[i-3]&&c[j][3]==a[i-2]&&c[j][4]==a[i]&&c[j][5]==a[i+1]&&c[j][6]==a[i+2]&&c[j][7]==a[i+3]){flag=0;d[j]++;break;}}if(flag){c[k][0]=a[i-6],c[k][1]=a[i-5],c[k][2]=a[i-3],c[k][3]=a[i-2],c[k][4]=a[i],c[k][5]=a[i+1],c[k][6]=a[i+2],c[k][7]=a[i+3];d[k]++;k++;}}}}}maxx=-1;t=0;for(i=0;i<k;i++){if(d[i]>maxx){maxx=d[i];t=i;}}printf("%c%c-%c%c-%c%c%c%c\n",c[t][0],c[t][1],c[t][2],c[t][3],c[t][4],c[t][5],c[t][6],c[t][7]);}return 0;
}

这是看着别人的代码写的。

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include <cctype>
#define N 200100
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int MAX=2e6+5;
char str[100005];
int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int cnt[4][16][32];
int main(){int d,m,y,id,ansd,len,i;d=m=y=-1;ansd=0;scanf("%s",str);len=strlen(str);for(i=0;i<len-9;i++){if(isdigit(str[i])&&isdigit(str[i+1])&&isdigit(str[i+3])&&isdigit(str[i+4])&&isdigit(str[i+6])&&isdigit(str[i+7])&&isdigit(str[i+8])&&isdigit(str[i+9])&&str[i+2]=='-'&&str[i+5]=='-'){d=(str[i+0]-48)*10+str[i+1]-48;m=(str[i+3]-48)*10+str[i+4]-48;y=(((str[i+6]-48)*10+str[i+7]-48)*10+str[i+8]-48)*10+str[i+9]-48;if(m>12||y<2013||y>2015||m<1)continue;if(d>month[m]||d<1)continue;if(++cnt[y-2013][m][d]>ansd){ansd=cnt[y-2013][m][d];id=i;}}}for(int i=0;i<10;i++)putchar(str[id+i]);return 0;
}

CodeForces - 260B Ancient Prophesy相关推荐

  1. Codeforces 260B - Ancient Prophesy

    260B - Ancient Prophesy 思路:字符串处理,把符合条件的答案放进map里,用string类中的substr()函数会简单一些,map中的值可以边加边记录答案,可以省略迭代器访问部 ...

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

    题干: A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy ...

  3. CodeForces - 260 - BAncient Prophesy(暴力)

    A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is ...

  4. B - Ancient Prophesy CodeForces - 260B

    第二次比赛,我感受到了我心态的问题,还有思维的缺陷把. 容易钻进死胡同. 这道题题意很简单,就是要去找符合条件的字符串. /*If I get TLE , it is good.If I get AC ...

  5. 【CodeForces 611D】Ancient Prophesy

    智障模拟.. 我也是智障.. 下面傻逼代码没有过.. #include<bits/stdc++.h> using namespace std; #define maxn 100100 ch ...

  6. Codeforces H. Ancient Wisdom

    题目链接:https://codeforces.com/gym/102365/problem/H H. Ancient Wisdom David and Aram had the following ...

  7. B. Ancient Prophesy(模拟)

    题目链接---- 题目大意是给你一个字符串,找到出现次数最多的日期格式.dd-mm-yyyy 而且  yyyy是在2013 - 2015,并且dd-mm-yyyy满足日期正确性. 思路:就是模拟,但是 ...

  8. python程序段的基本结构_python3 第三章 - 程序的基本结构

    1.编码 默认情况下,Python 3 源码文件以 UTF-8 编码,所有字符串都是 unicode 字符串. 当然你也可以为源码文件指定不同的编码: # -*- coding: cp-1252 -* ...

  9. Codeforces Good Bye 2015 D. New Year and Ancient Prophecy 后缀数组 树状数组 dp

    D. New Year and Ancient Prophecy 题目连接: http://www.codeforces.com/contest/611/problem/C Description L ...

最新文章

  1. 理解shared_ptrT
  2. 从分治算法到 MapReduce
  3. Kotlin 知识梳理(13) 运行时的泛型
  4. postgresql导入mysql_【原创】MySQL和PostgreSQL 导入数据对比
  5. SAP UI5 使用 Smart Control 的一个具体例子
  6. 数据库SQL语言从入门到精通--Part 2--MySQL安装
  7. 你知道“拉黑”、“关注”、“点赞”、“转发”、“分享到朋友圈”等英语咋说吗?
  8. tp5下通过composer实现日志记录功能
  9. 高德地图iOS SDK使用
  10. 理解_授权数据模型_Spring Security OAuth2.0认证授权---springcloud工作笔记112
  11. 分段锁——ConcurrentHashMap
  12. CSS美化超链接样式
  13. 您需要 TrustedInstaller 提供的权限才能对此文件进行更改
  14. LeetCode题解-6. ZigZag Conversion
  15. 【Vue】使用vue框架制作一个简单的网页
  16. 使用第三方打码平台图鉴识别滑动验证码模拟登录
  17. Material Design控件使用(二)
  18. python的cfg是什么模块_python操作cfg配置文件方式
  19. 医疗单据、医疗票据OCR识别接口
  20. android Stopwatch实例

热门文章

  1. 1024终极预告:0元领 +VIP免单+ 100% 中奖,没有套路,直降直减!
  2. 什么是云计算?云计算学习方向有哪些?
  3. 7、网络编程-TCP简介
  4. Vue的系列之详解生命周期
  5. 2018年 前端秋季校招面经
  6. HTML5 SVG纸屑按钮动画js特效
  7. Pycharm配置Gitee
  8. springboot:PO、VO、DAO、BO、DTO、POJO 你能分清吗?
  9. “元宇宙”忽然爆火,上万亿资本大量涌入,最后肥了谁的口袋?
  10. 餐饮界有福了,为海底捞服务的SaaS产品开始推向全行业