题目链接————

题目大意是给你一个字符串,找到出现次数最多的日期格式。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(模拟)相关推荐

  1. 【CodeForces - 260B 】Ancient Prophesy (暴力匹配,BF算法,日期字符串)

    题干: A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy ...

  2. CodeForces - 260B Ancient Prophesy

    CodeForces - 260B Ancient Prophesy A recently found Ancient Prophesy is believed to contain the exac ...

  3. Codeforces 260B - Ancient Prophesy

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

  4. 【CodeForces 611D】Ancient Prophesy

    智障模拟.. 我也是智障.. 下面傻逼代码没有过.. #include<bits/stdc++.h> using namespace std; #define maxn 100100 ch ...

  5. B - Ancient Prophesy CodeForces - 260B

    第二次比赛,我感受到了我心态的问题,还有思维的缺陷把. 容易钻进死胡同. 这道题题意很简单,就是要去找符合条件的字符串. /*If I get TLE , it is good.If I get AC ...

  6. CodeForces - 260 - BAncient Prophesy(暴力)

    A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is ...

  7. python程序段的基本结构_python3 第三章 - 程序的基本结构

    1.编码 默认情况下,Python 3 源码文件以 UTF-8 编码,所有字符串都是 unicode 字符串. 当然你也可以为源码文件指定不同的编码: # -*- coding: cp-1252 -* ...

  8. UVA - 1339 ​​​​​​​Ancient Cipher

    Ancient Cipher UVA - 1339 题目传送门 解决方法:模拟一下转换过程即可. AC代码: #include <cstdio> #include <iostream ...

  9. abc计算机发明英语翻译,英语四级翻译模拟练习:四大发明

    英语四级要做好翻译题,最重要的是平时的积累练习,只有多做才能轻松考取高分.下面是学习啦小编为大家带来英语四级翻译模拟练习及详解,希望对大家的学习有所帮助! 英语四级翻译模拟练习:四大发明 四大发明(t ...

最新文章

  1. Android之平台架构
  2. 机器学习之交叉验证方法详解【基于Scikit-Learn】
  3. cta策略 有哪些_【投资理财】基本面拐点已至,当前环境适合配置哪些策略?...
  4. 在Docker中运行SpringBoot程序
  5. java工程师_Java开发工程师需要掌握哪些技能?
  6. 以个人身份加入.NET基金会
  7. Think in Java第四版 读书笔记10 第16章 数组
  8. IndirectmodificationofoverloadedelementofXXXhasnoeffect的解决办法
  9. SLAM和三维重建中的SFM区别
  10. ffmpeg和mencoder实现视频转码
  11. unity 无法打包
  12. TrustedInstaller
  13. 刘强东第二次“二次创业”
  14. [Luogu1970] 花匠 [贪心/dp]
  15. MCU裸系统下快速平方根实现
  16. polyline与polygon
  17. 三元相分级统计地图-绘制-USDA soil textural triangle
  18. 【转官方】Android ADB调试命令、支持的命令、ADB文档
  19. RALL 与 智能指针
  20. bzoj4416 阶乘字符串 子集dp

热门文章

  1. R语言中的quantile()函数
  2. 《惢客创业日记》2020.07.13(周一)最短的一篇日记。
  3. 八电极脂肪秤方案软硬件与APP功能介绍
  4. Java项目开发中的DO、BO、DTO、VO、PO的区别
  5. IDEA的安装使用与技巧分享
  6. iTunes只能装C盘吗_安装win10系统时系统盘C盘分区多大空间适合?
  7. nginx-工作原理及配置文件详解<一>
  8. 机器学习是如何利用线性代数来解决数据问题的
  9. 克服以下几点障碍,建模技术飞升,羽化成仙指日可待!
  10. c# 创建一个pdf 将图片和文字存入PDF