统计字符数
发布日期:2021-05-12 21:40:42 浏览次数:10 分类:精选文章

本文共 1221 字,大约阅读时间需要 4 分钟。

���������������������������������������������������������������������������������������������������������������������������������������������ASCII���������������������

���������������

  • ������������������������ ������input().strip()���������������������������������������������
  • ��������������������������� ���������������26���������count���������������������������������������������
  • ������������������������������������ max_count���������������������������result_char���������������
  • ������������������ ���������������������������������������������������������
  • ��������������������������������� ������������������������������������max_count���������������������������������������������max_count���������������ASCII���������������������������
  • ��������������� ���������������������������������
  • ���������������

    s = input().strip()count = [0] * 26max_count = 0result_char = ''for char in s:    index = ord(char) - ord('a')    count[index] += 1    if count[index] > max_count:        max_count = count[index]        result_char = chr(index)    elif count[index] == max_count:        current_char = chr(index)        if ord(current_char) < ord(result_char):            result_char = current_charprint(f"{result_char} {max_count}")
    上一篇:求逆序对
    下一篇:出现次数超过一半的数

    发表评论

    最新留言

    表示我来过!
    [***.240.166.169]2025年04月08日 07时56分38秒