CF977B Two-gram

    • 52通过
    • 103提交
  • 题目来源 CodeForces 977B
  • 评测方式 RemoteJudge
  • 标签 字符串 枚举,暴力
  • 难度 普及-
  • 时空限制 1000ms / 256MB

题解

  • 提示:收藏到任务计划后,可在首页查看。
  • 体验新版界面

    最新讨论 显示

    推荐的相关题目 显示

    题意翻译

    给你一个字符串,找出现次数最多的长度为2的子串。

    题目描述

    Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "AZ", "AA", "ZA" — three distinct two-grams.

    You are given a string $ s $ consisting of $ n $ capital Latin letters. Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters of the string) maximal number of times. For example, for string $ s $ = "BBAABBBA" the answer is two-gram "BB", which contained in $ s $ three times. In other words, find any most frequent two-gram.

    Note that occurrences of the two-gram can overlap with each other.

    输入输出格式

    输入格式:

    The first line of the input contains integer number $ n $ ( $ 2 \le n \le 100 $ ) — the length of string $ s $ . The second line of the input contains the string $ s $ consisting of $ n $ capital Latin letters.

    输出格式:

    Print the only line containing exactly two capital Latin letters — any two-gram contained in the given string $ s $ as a substring (i.e. two consecutive characters of the string) maximal number of times.

    输入输出样例

    输入样例#1: 复制
    7
    ABACABA
    
    输出样例#1: 复制
    AB
    
    输入样例#2: 复制
    5
    ZZZAA
    
    输出样例#2: 复制
    ZZ
    

    说明

    In the first example "BA" is also valid answer.

    In the second example the only two-gram "ZZ" can be printed because it contained in the string "ZZZAA" two times.

    提示
    标程仅供做题后或实在无思路时参考。
    请自觉、自律地使用该功能并请对自己的学习负责。
    如果发现恶意抄袭标程,将按照I类违反进行处理。