牛客练习赛13 A 幸运数字Ⅰ 【暴力】
题目链接
https://www.nowcoder.com/acm/contest/70/A
思路
暴力每一个子串 用 MAP 标记一下 然后 最后 遍历一遍 MAP 找出 出现次数最多 并且 字典序最小的那个
AC代码
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long LL;
const double PI = 3.14159265358979323846264338327;
const double E = 2.718281828459;
const double eps = 1e-6;
const int MAXN = 0x3f3f3f3f;
const int MINN = 0xc0c0c0c0;
const int maxn = 1e5 + 5;
const int MOD = 1e9 + 7;
int main()
{
string s, temp;
cin >> s;
map <string, int> m;
m.clear();
int len = s.size();
for (int i = 0; i < len; i++)
{
if (s[i] == '4' || s[i] == '7')
{
temp.clear();
for (int j = i; j < len; j++)
{
temp += s[j];
m[temp]++;
}
}
}
map <string, int>::iterator it;
int Max = -1;
for (it = m.begin(); it != m.end(); it++)
{
if (it -> second > Max)
{
temp = it -> first;
Max = it -> second;
}
}
if (Max != -1)
cout << temp << endl;
else
cout << -1 << endl;
}
牛客练习赛13 A 幸运数字Ⅰ 【暴力】的更多相关文章
- 牛客练习赛13 B 幸运数字Ⅱ 【暴力】【二分】
题目链接 https://www.nowcoder.com/acm/contest/70/B 思路 没有代码限制 先打表 打出 幸运数字的表 然后 二分查找 第一个 大于 r 的幸运数字 然后 往 L ...
- 牛客网 牛客练习赛13 C.幸运数字Ⅲ-思维
C.幸运数字Ⅲ 链接:https://www.nowcoder.com/acm/contest/70/C来源:牛客网 这个题447和477是特殊的,其他的就没什么了. 代码: 1 #i ...
- 牛客网 牛客练习赛13 B.幸运数字Ⅱ-数组 or DFS
B.幸运数字Ⅱ 链接:https://www.nowcoder.com/acm/contest/70/B来源:牛客网 这个题就是找出来数据范围内的所有的幸运数,然后直接区间累加起来就可以了. ...
- 牛客网 牛客练习赛13 A.幸运数字Ⅰ
A.幸运数字Ⅰ 链接:https://www.nowcoder.com/acm/contest/70/A来源:牛客网 水题. 代码: #include<iostream> #i ...
- 牛客练习赛13D:幸运数字Ⅳ(康托展开) F:关键字排序
链接:https://www.nowcoder.com/acm/contest/70/D 题目: 定义一个数字为幸运数字当且仅当它的所有数位都是4或者7. 比如说,47.744.4都是幸运数字而5.1 ...
- 牛客练习赛31 D 神器大师泰兹瑞与威穆 STL,模拟 A
牛客练习赛31 D 神器大师泰兹瑞与威穆 https://ac.nowcoder.com/acm/contest/218/D 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 26214 ...
- 牛客练习赛28-B(线段树,区间更新)
牛客练习赛28 - B 传送门 题目 qn姐姐最好了~ qn姐姐给你了一个长度为n的序列还有m次操作让你玩, 1 l r 询问区间[l,r]内的元素和 2 l r 询问区间[l,r]内的 ...
- [堆+贪心]牛客练习赛40-B
传送门:牛客练习赛40 题面: 小A手头有 n 份任务,他可以以任意顺序完成这些任务,只有完成当前的任务后,他才能做下一个任务 第 i 个任务需要花费 x_i 的时间,同时完成第 i 个任务的时间不 ...
- 牛客练习赛48 C 小w的糖果 (数学,多项式,差分)
牛客练习赛48 C 小w的糖果 (数学,多项式) 链接:https://ac.nowcoder.com/acm/contest/923/C来源:牛客网 题目描述 小w和他的两位队友teito.toki ...
随机推荐
- STL学习笔记(非变动性算法)
辅助函数 本节跟以后几节将对所有STL算法逐一详细讨论.为了简化这些例子,我们使用了一些辅助函数,分别用于对容器进行输出跟插入操作. #ifndef ALGOSTUFF_HPP #define ALG ...
- python 读写数据
开源标准数据集 —— mnist(手写字符识别) 下载地址:mnist.pkl.gz 1. 使用 python 读取和解析 mnist.pkl.gz import pickle import gzip ...
- Google Code Jam 资格赛: Problem A. Magic Trick
Note: To advance to the next rounds, you will need to score 25 points. Solving just this problem wil ...
- 基于markdown的blog系统调研1:typecho
))
- 8168开发之---1g内存换成512M的内存映射配置
最近在帮新来同事调式内存分配,起初是将config.bld 中的内存在标配的基础上减少sr1,和tiler 将dsp从9m增加到16m,然后编译通过, 可是在加载的时候卡住了,init.sh 过,lo ...
- Hadoop编码解码【压缩解压缩】机制具体解释(1)
想想一下,当你须要处理500TB的数据的时候,你最先要做的是存储下来. 你是选择源文件存储呢?还是处理压缩再存储?非常显然,压缩编码处理是必须的.一段刚刚捕获的60分钟原始视屏可能达到2G,经过压缩处 ...
- web安全之SQL注入---第二章 什么是sql注入?
如何理解SQL注入?SQL注入是一种将SQL代码添加到输入参数中传递到SQL服务器解析并执行的一种攻击方法总结:其实就是输入的参数没有进行过滤,直接参加sql语句的运算,达到不可预想的结果.SQL注入 ...
- Java是否存在内存泄露
会的. 原因:长生命周期的对象持有短生命周期对象的引用,导致短生命周期对象不能被回收,由此可能发生内存泄露. 举例参考:http://blog.csdn.net/yakihappy/article/d ...
- javascript修改图片链接地址
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> < ...
- java并发编程基础---Sky
1.线程及启动和终止 1.1 线程 -进程/优先级 操作系统调度的最小单元是线程,线程是轻量级进程. 线程优先级由setPriority(int)方法来设置,默认优先级是5,等级1~10.等级越高分的 ...