zoukankan      html  css  js  c++  java
  • 洛谷 P6832 [Cnoi2020]子弦

    思路

    直接找出现最多次数的字母即可

    因为串越短,可能的出现次数就会越多,所以直接找出现次数最多的字母,输出出现次数即可

    代码

    #include <cmath>
    #include <queue>
    #include <cstdio>
    #include <vector>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    
    const int A = 1e7 + 11;
    const int B = 1e6 + 11;
    const int mod = 1e9 + 7;
    const int inf = 0x3f3f3f3f;
    
    inline int read() {
      char c = getchar();
      int x = 0, f = 1;
      for ( ; !isdigit(c); c = getchar()) if (c == '-') f = -1;
      for ( ; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
      return x * f;
    }
    
    char s[A];
    int ans, a[A];
    
    int main() {
      scanf("%s", s + 1);
      int n = strlen(s + 1);
      for (int i = 1; i <= n; i++) a[s[i] - 'a']++;
      for (int i = 0; i < 26; i++) ans = max(ans, a[i]);
      cout << ans << '
    ';
      return 0;
    }
    
  • 相关阅读:
    C语言I博客作业09
    请看这里
    C++ 面向对象学习笔记[1]
    graphviz的使用
    KDE安装后的一些随笔
    近期内容整理
    链表
    理解C++ lvalue与rvalue
    再看“笕实智慧校园”——作品的复盘[1]
    无题
  • 原文地址:https://www.cnblogs.com/loceaner/p/13706116.html
Copyright © 2011-2022 走看看