Codeforces 260B - Ancient Prophesy
思路:字符串处理,把符合条件的答案放进map里,用string类中的substr()函数会简单一些,map中的值可以边加边记录答案,可以省略迭代器访问部分。
代码:
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+;
map<string,int>mp;
string s;
int d[]={,,,,,,,,,,,};
bool isOK(string s)
{
if(s[]!='-'||s[]!='-')return false;
if(s[]=='-'||s[]=='-'||s[]=='-'||s[]=='-')return false;
int a=(s[]-'')*+s[]-'';
int b=(s[]-'')*+s[]-'';
if(b<=||b>)return false;
if(a<=||a>d[b-])return false;
return true;
}
int main()
{
cin>>s;
int cnt=;
string ans;
for(int i=;i<s.size()-;i++)
{
if(s[i]==''&&s[i+]==''&&s[i+]==''&&''<=s[i+]&&s[i+]<='')
{
string s1=s.substr(i-,);
if(isOK(s1))
{
string s2=s.substr(i-,);
mp[s2]++;
if(mp[s2]>cnt)
{
cnt=mp[s2];
ans=s2;
}
}
}
}
cout<<ans<<endl;
return ;
}
Codeforces 260B - Ancient Prophesy的更多相关文章
- [codeforces 260]B. Ancient Prophesy
[codeforces 260]B. Ancient Prophesy 试题描述 A recently found Ancient Prophesy is believed to contain th ...
- CodeForces - 260B
A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is ...
- Codeforces 1C Ancient Berland Circus
传送门 题意 给出一正多边形三顶点的坐标,求此正多边形的面积最小值. 分析 为了叙述方便,定义正多边形的单位圆心角u为正多边形的某条边对其外接圆的圆心角(即外接圆的某条弦所对的圆心角). (1)多边形 ...
- Codeforces 1045E. Ancient civilizations 构造 计算几何 凸包
原文链接https://www.cnblogs.com/zhouzhendong/p/CF1045E.html 4K码量构造题,CF血腥残暴! 题解 首先,如果所有点颜色相同,那么直接连个菊花搞定. ...
- Codeforces Round #158 (Div. 2)
A. Adding Digits 枚举. B. Ancient Prophesy 字符串处理. C. Balls and Boxes 枚举起始位置\(i\),显然\(a_i \le a_j, 1 \l ...
- kgcd ,fmod,fgcd
参考:NENU CS ACM模板made by tiankonguse 2.13 GCD 快速gcd: 位操作没学,真心不懂二进制,还是得学啊 code: int kgcd(){ if(!a || ...
- CodeForces 164 B. Ancient Berland Hieroglyphs 单调队列
B. Ancient Berland Hieroglyphs 题目连接: http://codeforces.com/problemset/problem/164/B Descriptionww.co ...
- 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 ...
- Codeforces Beta Round #1 C. Ancient Berland Circus 计算几何
C. Ancient Berland Circus 题目连接: http://www.codeforces.com/contest/1/problem/C Description Nowadays a ...
随机推荐
- Leetcode: Binary Tree Inorder Transversal
Given a binary tree, return the inorder traversal of its nodes' values. For example: Given binary tr ...
- Multinoulli distribution
https://www.statlect.com/probability-distributions/multinoulli-distribution3 Multinoulli distributio ...
- Python: dict setdault函数与collections.defaultdict()的区别
setdault用法 >>>dd={'hy':1,'hx':2} >>>cc=dd.setdefault('hz',1) >>>cc 返 ...
- 关于 enhanced decompiler 3.0 .0不起作用的解决办法
- ES6之前模拟Map数据结构的写法
在ES6之前JavaScript 里面本身没有map对象,但是用JavaScript的Array.Object来模拟实现Map的数据结构. 现在已经有Map对象了,这里记录一下之前的写法 Array方 ...
- ELK+Kafka学习笔记之搭建ELK+Kafka日志收集系统集群
0x00 概述 关于如何搭建ELK部分,请参考这篇文章,https://www.cnblogs.com/JetpropelledSnake/p/9893566.html. 该篇用户为非root,使用用 ...
- 散列表(HashTable)
散列表 i. 散列函数 i. 冲突解决 ii. 分离链表法 ii. 开放地址法 iii. 线性探测法 iii. 平方探测法 iii. 双散列 ii. 再散列 ii. 可扩散列 i. 装填因子:元素个数 ...
- C++微专业课程辅导(内存模型和动态内存)
“除了静态内存和栈内存之外,每个程序还拥有一个内存池.这部分空间被称作自由空间(free store)或堆(heap).程序用堆来存储动态分配(dynamically allocate)的对象”——& ...
- 06: AJAX全套 & jsonp跨域AJAX
目录: 1.1 AJAX介绍 1.2 jQuery AJAX(第一种) 1.3 原生ajax(第二种) 1.4 iframe“伪”AJAX(第三种) 1.5 jsonp跨域请求 1.6 在tornad ...
- Asterisk1.8 sip编码协商分析
在开始分析之前,先对编码协商中可能涉及的asterisk数据结构和变量作些说明.ast_channel:定义一个通用的通道数据结构 struct ast_channel { const struct ...