[codeforces 260]B. Ancient Prophesy
[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.
输出
输入示例
--------------
输出示例
--
数据规模及约定
见“输入”
题解
扫一遍字符串,然后 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的更多相关文章
- Codeforces 260B - Ancient Prophesy
260B - Ancient Prophesy 思路:字符串处理,把符合条件的答案放进map里,用string类中的substr()函数会简单一些,map中的值可以边加边记录答案,可以省略迭代器访问部 ...
- CodeForces 164 B. Ancient Berland Hieroglyphs 单调队列
B. Ancient Berland Hieroglyphs 题目连接: http://codeforces.com/problemset/problem/164/B Descriptionww.co ...
- Codeforces 260 C. Boredom
题目链接:http://codeforces.com/contest/456/problem/C 解题报告:给出一个序列,然后选择其中的一个数 k 删除,删除的同时要把k - 1和k + 1也删除掉, ...
- Codeforces 260 B. Fedya and Maths
题目链接:http://codeforces.com/contest/456/problem/B 解题报告:输入一个n,让你判断(1n + 2n + 3n + 4n) mod 5的结果是多少?注意n的 ...
- Codeforces 260 A - A. Laptops
题目链接:http://codeforces.com/contest/456/problem/A 解题报告:有n种电脑,给出每台电脑的价格和质量,要你判断出有没有一种电脑的价格小于另一种电脑但质量却大 ...
- codeforces #260 DIV 2 C题Boredom(DP)
题目地址:http://codeforces.com/contest/456/problem/C 脑残了. .DP仅仅DP到了n. . 应该DP到10w+的. . 代码例如以下: #include & ...
- 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 ...
- CodeForces - 1C:Ancient Berland Circus (几何)
Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things ...
- codeforces 260 div2 C题
C题就是个dp,把原数据排序去重之后得到新序列,设dp[i]表示在前i个数中取得最大分数,那么: if(a[i] != a[i-1]+1) dp[i] = cnt[a[i]]*a[i] + dp[ ...
随机推荐
- Java学习笔记(十五)——javadoc学习笔记和可能的注意细节
[前面的话] 这次开发项目使用jenkins做持续集成,PMD检查代码,Junit做单元测试,还会自动发邮件通知编译情况,会将javadoc生成的文档自动发到一个专门的服务器上面,每个人都可以看,所以 ...
- Linq之Lambda进阶
目录 写在前面 系列文章 带有标准查询运算符的Lambda Lambda中类型推断 Lambda表达式中变量作用域 异步Lambda 总结 写在前面 上篇文章介绍了Lambda的基本概念以及匿名方法, ...
- NumberFormat类的用法
NumberFormat.getInstance()方法返回NumberFormat的一个实例(实际上是NumberFormat具体的一个子类,例如DecimalFormat), 这适合根据本地设置格 ...
- iOS开发小技巧--利用苹果官方API播放视频(方法已经过时,了解一下)
- hdu1561 树形dp + 背包
#include<cstdio> #include<cstring> #include<iostream> #define INF 999999999 using ...
- CXF WebService 资料收集
Java Web 服务专题 :http://www.ibm.com/developerworks/cn/java/j-ws/ APACHE CXF官网 :http://cxf.apache.org/d ...
- 【poj1201】 Intervals
http://poj.org/problem?id=1201 (题目链接) 题意 给出n个区间${[ai,bi]}$,要求选出尽可能少的数,使得每个区间i中至少存在${c[i]}$个数. Soluti ...
- shopex商城的部署和安装
1.在网站上下载最新的压缩包: 2.shopex是商业软件,不开源,且源代码是加密的! 3.如果你出现zend的错误,是因为你的php环境没有安装此插件,推荐使用phpstudy最新版本,我使用的ph ...
- Nginx Installation、Configuration、Rreverse Proxy、Load Balancing Learning
目录 . Nginx简介 . Nginx安装部署 . Nginx安全配置 . Nginx反向代理实践 . Nginx负载均衡实践 1. Nginx简介 0x1: Nginx的基本特性 Nginx(&q ...
- 用word写博客
都知道word的编辑功能强大,那如何用word写博客呢? 以博客园为例 1.写好word文档后,文件->共享->发送至博客,或者新建博客模板 2. 再博客的界面点击管理账户,新建账户,如果 ...