[codeforces 260]B. 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.

输入

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.

输出

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

输入示例

--------------

输出示例

--

数据规模及约定

见“输入

题解

扫一遍字符串,然后 string, map STL 大法好,反正 cf 测评机快的飞起。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <set>
using namespace std; const int BufferSize = 1 << 16;
char buffer[BufferSize], *Head, *Tail;
inline char Getchar() {
if(Head == Tail) {
int l = fread(buffer, 1, BufferSize, stdin);
Tail = (Head = buffer) + l;
}
return *Head++;
}
int read() {
int x = 0, f = 1; char c = getchar();
while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
return x * f;
} #define maxn 100010
#define id isdigit
int n;
char S[maxn], tmp[15];
map <string, int> M; bool jud(char* s) {
// printf("%s\n", s + 1);
int d, m, y;
if(!id(s[1]) || !id(s[2]) || s[3] != '-' || !id(s[4]) || !id(s[5]) || s[6] != '-' || !id(s[7]) || !id(s[8]) || !id(s[9]) || !id(s[10]))
return 0;
d = (s[1] - '0') * 10 + s[2] - '0';
m = (s[4] - '0') * 10 + s[5] - '0';
y = (s[7] - '0') * 1000 + (s[8] - '0') * 100 + (s[9] - '0') * 10 + s[10] - '0';
// printf("%d %d %d\n", d, m, y);
if(y < 2013 || y > 2015) return 0;
if(m < 1 || m > 12 || d < 1) return 0;
if(m == 2 && d > 28) return 0;
if(m <= 7 && (m & 1) && d > 31) return 0;
if(m <= 7 && !(m & 1) && d > 30) return 0;
if(m > 7 && !(m & 1) && d > 31) return 0;
if(m > 7 && (m & 1) && d > 30) return 0;
return 1;
} int main() {
scanf("%s", S + 1); n = strlen(S + 1); int mx = 0; string mxs = "";
for(int i = 1; i <= n - 9; i++) {
memset(tmp, 0, sizeof(tmp));
for(int j = i; j <= i + 9; j++) tmp[j-i+1] = S[j];
if(jud(tmp)) {
string tt = string(tmp + 1);
if(!M.count(tt)) M[tt] = 1;
else M[tt]++;
if(mx < M[tt]) mx = M[tt], mxs = tt;
}
} cout << mxs << endl; return 0;
}

[codeforces 260]B. Ancient Prophesy的更多相关文章

  1. Codeforces 260B - Ancient Prophesy

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

  2. CodeForces 164 B. Ancient Berland Hieroglyphs 单调队列

    B. Ancient Berland Hieroglyphs 题目连接: http://codeforces.com/problemset/problem/164/B Descriptionww.co ...

  3. Codeforces 260 C. Boredom

    题目链接:http://codeforces.com/contest/456/problem/C 解题报告:给出一个序列,然后选择其中的一个数 k 删除,删除的同时要把k - 1和k + 1也删除掉, ...

  4. Codeforces 260 B. Fedya and Maths

    题目链接:http://codeforces.com/contest/456/problem/B 解题报告:输入一个n,让你判断(1n + 2n + 3n + 4n) mod 5的结果是多少?注意n的 ...

  5. Codeforces 260 A - A. Laptops

    题目链接:http://codeforces.com/contest/456/problem/A 解题报告:有n种电脑,给出每台电脑的价格和质量,要你判断出有没有一种电脑的价格小于另一种电脑但质量却大 ...

  6. codeforces #260 DIV 2 C题Boredom(DP)

    题目地址:http://codeforces.com/contest/456/problem/C 脑残了. .DP仅仅DP到了n. . 应该DP到10w+的. . 代码例如以下: #include & ...

  7. Codeforces 1 C. Ancient Berland Circus-几何数学题+浮点数求gcd ( Codeforces Beta Round #1)

    C. Ancient Berland Circus time limit per test 2 seconds memory limit per test 64 megabytes input sta ...

  8. CodeForces - 1C:Ancient Berland Circus (几何)

    Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things ...

  9. codeforces 260 div2 C题

    C题就是个dp,把原数据排序去重之后得到新序列,设dp[i]表示在前i个数中取得最大分数,那么: if(a[i] != a[i-1]+1)   dp[i] = cnt[a[i]]*a[i] + dp[ ...

随机推荐

  1. offsetWidth与scrollLeft

    有两个值一个是:scrollTop一个是scrollLeft第一个代表页面利用滚动条滚动到下方时,隐藏在滚动条上方的页面的高度:第二个代表页面利用滚动条滚动到右侧时,隐藏在滚动条左侧的页面的宽度 do ...

  2. JavaScript事件---事件入门

    内容提纲: 1.事件介绍 2.内联模型 3.脚本模型 4.事件处理函数 JavaScript事件是由访问Web页面的用户引起的一系列操作,例如:用户点击.当用户执行某些操作的时候,再去执行一系列代码. ...

  3. 传说中的WeixinJSBridge和微信rest接口

    直接上图,金山的APP“微信导航”,从界面上看有粉丝数等关键数据,实现了直接关注功能,莫不是rest接口?这江湖是大佬们的江湖,小喽啰只有眼馋的份咯. 很早就听说过WeixinJSBridge,不过官 ...

  4. photoshop将psd导出div+css格式HTML(自动)

    psd切片切好后,导出 web格式,存储时选择html.所有切片,然后,选择其他,选择自定,选择切片,选择生成css css命名有2种方式,根据ID和根据类,一般选择根据类(ID尽量少有,防止js要用 ...

  5. [转]java基础学习总结——equals方法

    一.equals方法介绍 1.1.通过下面的例子掌握equals的用法 1 package cn.galc.test; 2 3 public class TestEquals { 4 public s ...

  6. hdu1535 SPFA

    2边SPFA 然后求和 #include<stdio.h> #include<string.h> #include<queue> #define INF 10000 ...

  7. Java异常分类

    一.基本概念 看java的异常结构图 Throwable是所有异常的根,java.lang.ThrowableError是错误,java.lang.ErrorException是异常,java.lan ...

  8. 左偏树(DP)问题

    问题:A straight dirt road connects two fields on FJ's farm, but it changes elevation more than FJ woul ...

  9. POJ-2777Count Color 线段树+位移

    这道题对于我这样的初学者还是有点难度的不过2遍A了还是很开心,下面说说想法-- Count Color Time Limit: 1000MS Memory Limit: 65536K Total Su ...

  10. SpringMVC配置

    博客园 闪存 首页 新随笔 联系 管理 订阅 随笔- 4  文章- 1  评论- 0  搭建springmvc框架的另一种思路 在一个完整的项目里搭建springmvc框架的时候, 通常情况下,初学者 ...