[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[ ...
随机推荐
- 回归到最初的编程——Linux下的C编程
最近感觉有些浮躁,一方面感觉最近写公司的PHP代码倍感无聊,没有什么成就感!另一方面面对我的mac电脑中安装了诸多开发语言,倍感浮躁与困惑!同时想到这么多年来,却一直在使用PHP进行程序开发,总觉得有 ...
- 简单的3个SQL视图搞定所有SqlServer数据库字典
网上有很多SQL SERVER数据库字典的SQL语句,七零八落,我在工作整理了一下思路,总结SQL代码如下.数据库字典包括表结构(分2K和2005).索引和主键.外键.约束.视图.函数.存储过程.触发 ...
- 《TCP/IP详解卷1:协议》第17、18章 TCP:传输控制协议(1)-读书笔记
章节回顾: <TCP/IP详解卷1:协议>第1章 概述-读书笔记 <TCP/IP详解卷1:协议>第2章 链路层-读书笔记 <TCP/IP详解卷1:协议>第3章 IP ...
- [C#]Hosting Process (vshost.exe)
写在前面 最近在群里,有朋友问起这个vshost.exe进程到底是什么?当时确实不知道是个什么东东,给人的感觉是,经常看到它,就是在启动一个项目的时候,经常看到它,就是没细研究它是啥玩意儿.既然遇到了 ...
- Bootstrap3.0学习第二十二轮(JavaScript插件——弹出框)
详情请查看http://aehyok.com/Blog/Detail/28.html 个人网站地址:aehyok.com QQ 技术群号:206058845,验证码为:aehyok 本文文章链接:ht ...
- Struts2 数据校验流程
- nginx root && alias 文件路径配置
文章摘自:http://www.ttlsa.com/nginx/nginx-root_alias-file-path-configuration/ nginx指定文件路径有两种方式root和alias ...
- Java-集合类汇总
结构图: Collection ├List │├LinkedList │├ArrayList │└Vector │ └Stack └Set Map ├Hashtable ├HashMap └WeakH ...
- Java设计模式-适配器模式(Adapter)
适配器模式将某个类的接口转换成客户端期望的另一个接口表示,目的是消除由于接口不匹配所造成的类的兼容性问题.主要分为三类:类的适配器模式.对象的适配器模式.接口的适配器模式.首先,我们来看看类的适配器模 ...
- C语言浮点数除法可以精确到多少位小数
double型的两个数相除,得到的浮点数能精确到多少位呢..用我家电脑做了个实验,编译器是Code::Blocks 13.12. 然后用电脑自带的计算器算的结果和C语言算的结果比较如图. 第一例里a= ...