B. Ancient Prophesy(模拟)
题目链接————
题目大意是给你一个字符串,找到出现次数最多的日期格式。dd-mm-yyyy
而且 yyyy是在2013 - 2015,并且dd-mm-yyyy满足日期正确性。
思路:就是模拟,但是有许多注意的点,首先2013 - 1015都不是闰年,然后天数dd要>=1(忘判了。。。),<=本月的天数。
AC Code:
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<bitset>
#include<cctype>
#define LL long long
#define ULL unsigned long long
#define maxn (LL)1e5
#define INF 0x3f3f3f3f
#define inf 0x7fffffff
#define PI acos(-1.0)
#define is(x) isdigit(x)
#define pb push_back
#define re register LL
const double eps = 0.0000001;
using namespace std;
typedef pair<LL,LL> pii;
inline LL sgn(double x)
{return (x > eps) - (x < -eps);
}
char c[maxn+5];
map<string,int> st;
int sum[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
int main()
{stringstream ss;int y,m,d;string res;ios::sync_with_stdio(false);cin>>(c+1);int MAX = 0;int l =strlen(c+1);for(int i = 3; i<=l - 7; ++i){if(c[i]=='-'){if(is(c[i - 1])&&is(c[i - 2])&&is(c[i+1])&&is(c[i+2])&&c[i+3]=='-'&&is(c[i+4])&&is(c[i+5])&&is(c[i+6])&&is(c[i+7])){string s(c+i+4,c+i+8);ss<<s;ss>>y;ss.clear();string sss(c+i+1,c+i+3);ss<<sss;ss>> m;ss.clear();string ssss(c+i-2,c+i);ss<<ssss;ss>>d;ss.clear();// cout<<y<<" "<<m<<" "<<d<<endl;if(m<=12&&m>=1&&y>=2013&&y<=2015){m = sum[m];if(d<=m&&d>=1){string A(c+i-2,c+i+8);st[A]++;if(st[A]>MAX){MAX = st[A];res = A;}}}}}}cout<<res<<endl;}
CFdalao的Code总是那么简洁
AC Code:
#include<bits/stdc++.h>
using namespace std;
map<string,int>mp;
const int day[15]= {0,31,28,31,30,31,30,31,31,30,31,30,31};
int n=0,y,m,d,j;
string str,v,x;
int main()
{cin>>str;for(int i=0; i+10<=str.length(); i++){x=str.substr(i,10);if(sscanf((x+"*1").c_str(),"%2d-%2d-%4d*%d",&d,&m,&y,&j)!=4)continue;if(y<2013||y>2015||m<1||m>12||d<1||d>day[m])continue;mp[x]++;if(n<mp[x])n=mp[x],v=x;}cout<<v<<endl;return 0;
}
B. Ancient Prophesy(模拟)相关推荐
- 【CodeForces - 260B 】Ancient Prophesy (暴力匹配,BF算法,日期字符串)
题干: A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy ...
- CodeForces - 260B Ancient Prophesy
CodeForces - 260B Ancient Prophesy A recently found Ancient Prophesy is believed to contain the exac ...
- Codeforces 260B - Ancient Prophesy
260B - Ancient Prophesy 思路:字符串处理,把符合条件的答案放进map里,用string类中的substr()函数会简单一些,map中的值可以边加边记录答案,可以省略迭代器访问部 ...
- 【CodeForces 611D】Ancient Prophesy
智障模拟.. 我也是智障.. 下面傻逼代码没有过.. #include<bits/stdc++.h> using namespace std; #define maxn 100100 ch ...
- B - Ancient Prophesy CodeForces - 260B
第二次比赛,我感受到了我心态的问题,还有思维的缺陷把. 容易钻进死胡同. 这道题题意很简单,就是要去找符合条件的字符串. /*If I get TLE , it is good.If I get AC ...
- CodeForces - 260 - BAncient Prophesy(暴力)
A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is ...
- python程序段的基本结构_python3 第三章 - 程序的基本结构
1.编码 默认情况下,Python 3 源码文件以 UTF-8 编码,所有字符串都是 unicode 字符串. 当然你也可以为源码文件指定不同的编码: # -*- coding: cp-1252 -* ...
- UVA - 1339 Ancient Cipher
Ancient Cipher UVA - 1339 题目传送门 解决方法:模拟一下转换过程即可. AC代码: #include <cstdio> #include <iostream ...
- abc计算机发明英语翻译,英语四级翻译模拟练习:四大发明
英语四级要做好翻译题,最重要的是平时的积累练习,只有多做才能轻松考取高分.下面是学习啦小编为大家带来英语四级翻译模拟练习及详解,希望对大家的学习有所帮助! 英语四级翻译模拟练习:四大发明 四大发明(t ...
最新文章
- Android之平台架构
- 机器学习之交叉验证方法详解【基于Scikit-Learn】
- cta策略 有哪些_【投资理财】基本面拐点已至,当前环境适合配置哪些策略?...
- 在Docker中运行SpringBoot程序
- java工程师_Java开发工程师需要掌握哪些技能?
- 以个人身份加入.NET基金会
- Think in Java第四版 读书笔记10 第16章 数组
- IndirectmodificationofoverloadedelementofXXXhasnoeffect的解决办法
- SLAM和三维重建中的SFM区别
- ffmpeg和mencoder实现视频转码
- unity 无法打包
- TrustedInstaller
- 刘强东第二次“二次创业”
- [Luogu1970] 花匠 [贪心/dp]
- MCU裸系统下快速平方根实现
- polyline与polygon
- 三元相分级统计地图-绘制-USDA soil textural triangle
- 【转官方】Android ADB调试命令、支持的命令、ADB文档
- RALL 与 智能指针
- bzoj4416 阶乘字符串 子集dp