Codeforces 260B - Ancient Prophesy
260B - Ancient Prophesy
思路:字符串处理,把符合条件的答案放进map里,用string类中的substr()函数会简单一些,map中的值可以边加边记录答案,可以省略迭代器访问部分。
代码:
#include<bits/stdc++.h> using namespace std; const int N=1e5+5; map<string,int>mp; string s; int d[12]={31,28,31,30,31,30,31,31,30,31,30,31}; bool isOK(string s) {if(s[2]!='-'||s[5]!='-')return false;if(s[0]=='-'||s[1]=='-'||s[3]=='-'||s[4]=='-')return false;int a=(s[0]-'0')*10+s[1]-'0';int b=(s[3]-'0')*10+s[4]-'0';if(b<=0||b>12)return false;if(a<=0||a>d[b-1])return false;return true; } int main() {cin>>s;int cnt=0;string ans;for(int i=6;i<s.size()-3;i++){if(s[i]=='2'&&s[i+1]=='0'&&s[i+2]=='1'&&'3'<=s[i+3]&&s[i+3]<='5'){string s1=s.substr(i-6,6);if(isOK(s1)){string s2=s.substr(i-6,10);mp[s2]++;if(mp[s2]>cnt){cnt=mp[s2];ans=s2;}}}}cout<<ans<<endl;return 0; }
转载于:https://www.cnblogs.com/widsom/p/7205556.html
Codeforces 260B - Ancient Prophesy相关推荐
- CodeForces - 260B Ancient Prophesy
CodeForces - 260B Ancient Prophesy A recently found Ancient Prophesy is believed to contain the exac ...
- 【CodeForces - 260B 】Ancient Prophesy (暴力匹配,BF算法,日期字符串)
题干: A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy ...
- CodeForces - 260 - BAncient Prophesy(暴力)
A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is ...
- B - Ancient Prophesy CodeForces - 260B
第二次比赛,我感受到了我心态的问题,还有思维的缺陷把. 容易钻进死胡同. 这道题题意很简单,就是要去找符合条件的字符串. /*If I get TLE , it is good.If I get AC ...
- 【CodeForces 611D】Ancient Prophesy
智障模拟.. 我也是智障.. 下面傻逼代码没有过.. #include<bits/stdc++.h> using namespace std; #define maxn 100100 ch ...
- Codeforces H. Ancient Wisdom
题目链接:https://codeforces.com/gym/102365/problem/H H. Ancient Wisdom David and Aram had the following ...
- B. Ancient Prophesy(模拟)
题目链接---- 题目大意是给你一个字符串,找到出现次数最多的日期格式.dd-mm-yyyy 而且 yyyy是在2013 - 2015,并且dd-mm-yyyy满足日期正确性. 思路:就是模拟,但是 ...
- python程序段的基本结构_python3 第三章 - 程序的基本结构
1.编码 默认情况下,Python 3 源码文件以 UTF-8 编码,所有字符串都是 unicode 字符串. 当然你也可以为源码文件指定不同的编码: # -*- coding: cp-1252 -* ...
- Codeforces Good Bye 2015 D. New Year and Ancient Prophecy 后缀数组 树状数组 dp
D. New Year and Ancient Prophecy 题目连接: http://www.codeforces.com/contest/611/problem/C Description L ...
最新文章
- ORACLE11g 前期安装环境配置
- xcode6 AsynchronousTesting 异步任务测试
- ANSYS报错Accelerations are exceeding internal limit解决方法
- idea工程本地依赖_IDEA最新版2020.1的maven工程本地依赖仓库无法使用问题(已解决)...
- python删除空值多于50%的行_删除Pandas中“空”值超过60%的列
- 如果让我重做一次研究生--王泛森院士
- Redis主从配置详细过程
- Django-04-路由系统
- 阿里舆情︱舆情热词分析架构简述(Demo学习)
- Create Material by BDC and BAPI
- educoder 软件工程导论 结构化分析方法-数据流图
- 2017年第六届数学中国数学建模国际赛(小美赛)比赛心得
- java/php/net/python房产信息管理系统设计
- 利用百度点击原理提升关键词排名
- vue-router仿天猫底部导航栏
- android 后台运行清理,【Android】App在后台被清理后的终极应对手段——重启应用...
- VIVO NEX 3 5G版上手评测,除99.6%的屏占比,还有什么理由入手
- APP国际化、动态设置控件颜色(APP个性化)
- 【STM8】两个单片机之间的Lora通讯实验
- PaddlePaddle - 人脸关键点检测课程笔记