[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.

输入示例

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

输出示例

13-12-2013

数据规模及约定

见“输入

题解

扫一遍字符串,然后 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;
}
时间: 2024-10-08 07:25:10

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

Codeforces 260

A Problem description 给出数a,b,n,在a后加上1个数,并使加后的数是b的倍数.输出操作n次后的数. Data Limit:1?≤?a,?b,?n?≤?105  Time Limit: 1s Solution 易得只要第一次成功,剩下加0,就可以了 Code #include<cstdio> long long a,b,n,i,j; long long ans[500000];bool bo=false; int main() { scanf("%lld%ll

CodeForces - 260B

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 Pr

Codeforces Round #260 (Div. 2)

A. Laptops 题目意思: 给定n台电脑,第i台电脑的价格是ai ,质量是bi ,问是否存在一台电脑价格比某台电脑价格底,但质量确比某台电脑的质量高,即是否存在ai < aj 且 bi > bj ? 解题思路: 这题一定要看题目,a都是1~n的不同数,b也是1~n的不同数,此题只需要判断ai 是否等于bi ,如果ai != bi 的话,则输出“Happy Alex”,如果所有的ai  == bi 则输出“Poor Alex” 证明:先将a按照从小到大排序,当i<j时ai <

Codeforces Round #260 (Div. 1) A. Boredom (DP)

题目链接:http://codeforces.com/problemset/problem/455/A A. Boredom time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Alex doesn't like boredom. That's why whenever he gets bored, he comes up with

Codeforces Round #260(div2)C(递推)

有明显的递推关系: f[i]表示i为数列中最大值时所求结果.num[i]表示数i在数列中出现了几次. 对于数i,要么删i,要么删i-1,只有这两种情况,且子问题还是一样的思路.那么很显然递推一下就行了:f[i]=max(f[i-1],f[i-2]+i*num[i]); 这里技巧在于:为了防止麻烦,干脆就所有数的出现次数都记录一下,然后直接从2推到100000(类似于下标排序),就不用排序了,也不用模拟删除操作了.这一技巧貌似简单,但实际上临场想出来也需要点水平. #include<iostrea

dp解Codeforces Round #260 (Div. 2)C. Boredom

#include<iostream> #include<map> #include<string> #include<cstring> #include<cstdio> #include<cstdlib> #include<cmath> #include<queue> #include<vector> #include<algorithm> using namespace std; lo

递推DP Codeforces Round #260 (Div. 1) A. Boredom

题目传送门 1 /* 2 DP:从1到最大值,dp[i][1/0] 选或不选,递推更新最大值 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <cmath> 7 #include <cstring> 8 using namespace std; 9 10 typedef long long ll; 11 const int MAXN = 1e5 + 10; 12 const int INF

Codeforces Round #260 (Div. 2) A. Laptops(简单题)

题目链接:http://codeforces.com/problemset/problem/456/A A. Laptops time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output One day Dima and Alex had an argument about the price and quality of laptops.

Codeforces Round #260 (Div. 2) B. Fedya and Maths(循环节)

题目链接:http://codeforces.com/problemset/problem/456/B B. Fedya and Maths time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Fedya studies in a gymnasium. Fedya's maths hometask is to calculate t