CF977B.Two-gram

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 ss consisting of nn 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 ss = "BBAABBBA" the answer is two-gram "BB", which contained in ss three times. In other words, find any most frequent two-gram.

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

二元组(two-gram)是指一个有序对(即长度为 2 的字符串),由大写拉丁字母组成。例如,“AZ”、“AA”、“ZA” 是三个不同的二元组。

给定一个由 nn 个大写拉丁字母组成的字符串 ss。你的任务是在该字符串中找出任意一个作为子串(即字符串中两个连续的字符)出现次数最多的二元组。例如,对于字符串 s=“BBAABBBA”s = \text{“BBAABBBA”},答案是二元组 “BB”,它在 ss 中出现了三次。换言之,请找出任意一个出现频率最高的二元组。

注意:二元组的出现位置可以相互重叠。

输入格式

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

输入的第一行包含一个整数 nn(2≤n≤1002 \le n \le 100)—— 字符串 ss 的长度。
输入的第二行包含字符串 ss,由 nn 个大写拉丁字母组成。

输出格式

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

输出唯一一行,包含恰好两个大写拉丁字母——即字符串 ss 中作为子串(即字符串中两个连续字符)出现次数最多的任意一个二元组。

输入输出样例

  • 输入#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.

在第一个例子中,“BA”也是一个有效的答案。

在第二个例子中,唯一的二元组“ZZ”可以被输出,因为它在字符串“ZZZAA”中出现了两次。

输入解题思路,AI测评打分。不知道怎么写?

首页