我是靠谱客的博主 整齐紫菜,最近开发中收集的这篇文章主要介绍牛客练习赛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 A 幸运数字Ⅰ 【暴力】所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(56)

评论列表共有 0 条评论

立即
投稿
返回
顶部