【PAT】B1042 字符统计(20 分)

/*
    15分的题很简单,但是自己写的时候在输入数据时没有考虑好下标
    另外有忘记了输入字符时考虑是否有\n
*/
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<ctype.h>
using namespace std;
int main(){
    char str[1005];
    int arr[26]={0};
    scanf("%[^\n]",str);
    int len=strlen(str);
    for(int i=0;i<len;i++){
        if(isupper(str[i]))
            str[i]+=32;
        if(islower(str[i])){
            arr[str[i]-‘a‘]++;
        }
    }
    int flag=0;
    for(int i=0;i<26;i++)
        if(arr[flag]<arr[i])
            flag=i;
    printf("%c %d",‘a‘+flag,arr[flag]);
    return  0;
}

原文地址:https://www.cnblogs.com/hebust/p/9498023.html

时间: 2024-07-29 20:55:59

【PAT】B1042 字符统计(20 分)的相关文章

PAT B1042 字符统计

PAT B1042 字符统计 题目描述: 请编写程序,找出一段给定文字中出现最频繁的那个英文字母. 输入格式: 输入在一行中给出一个长度不超过 1000 的字符串.字符串由 ASCII 码表中任意可见字符及空格组成,至少包含 1 个英文字母,以回车结束(回车不算在内). 输出格式: 在一行中输出出现频率最高的那个英文字母及其出现次数,其间以空格分隔.如果有并列,则输出按字母序最小的那个字母.统计时不区分大小写,输出小写字母. 输入样例: This is a simple TEST.  There

PTA乙级 (1042 字符统计 (20分))

1042 字符统计 (20分) https://pintia.cn/problem-sets/994805260223102976/problems/994805280817135616 #include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <cstring> #include <string> using namesp

PAT 1042. 字符统计(20)

请编写程序,找出一段给定文字中出现最频繁的那个英文字母. 输入格式: 输入在一行中给出一个长度不超过1000的字符串.字符串由ASCII码表中任意可见字符及空格组成,至少包含1个英文字母,以回车结束(回车不算在内). 输出格式: 在一行中输出出现频率最高的那个英文字母及其出现次数,其间以空格分隔.如果有并列,则输出按字母序最小的那个字母.统计时不区分大小写,输出小写字母. 输入样例: This is a simple TEST. There ARE numbers and other symbo

PAT 乙级 1042 字符统计(20) C++版

1042. 字符统计(20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 请编写程序,找出一段给定文字中出现最频繁的那个英文字母. 输入格式: 输入在一行中给出一个长度不超过1000的字符串.字符串由ASCII码表中任意可见字符及空格组成,至少包含1个英文字母,以回车结束(回车不算在内). 输出格式: 在一行中输出出现频率最高的那个英文字母及其出现次数,其间以空格分隔.如果有并列,则输出按字母序最小的那个字

pat 1035 Password(20 分)

1035 Password(20 分) To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem is that there are always some confusing passwords since it is hard to distinguish 1 (one) from l (L in lowercase), or 0 (zero) fro

PAT 1042. 字符统计

1042. 字符统计 请编写程序,找出一段给定文字中出现最频繁的那个英文字母. 输入格式: 输入在一行中给出一个长度不超过1000的字符串.字符串由ASCII码表中任意可见字符及空格组成,至少包含1个英文字母,以回车结束(回车不算在内). 输出格式: 在一行中输出出现频率最高的那个英文字母及其出现次数,其间以空格分隔.如果有并列,则输出按字母序最小的那个字母.统计时不区分大小写,输出小写字母. 输入样例: This is a simple TEST. There ARE numbers and

pat 1077 Kuchiguse(20 分) (字典树)

1077 Kuchiguse(20 分) The Japanese language is notorious for its sentence ending particles. Personal preference of such particles can be considered as a reflection of the speaker's personality. Such a preference is called "Kuchiguse" and is often

[PTA] PAT(A) 1008 Elevator (20 分)

目录 Problem Description Input Output Sample Sample Input Sample Output Solution Analysis Code Problem portal: 1008 Elevator (20 分) Description  The highest building in our city has only one elevator. A request list is made up with $N$ positive numbers

PAT乙级1088-----三人行 (20分)

1088 三人行 (20分) 输入样例 1: 48 3 7 输出样例 1: 48 Ping Cong Gai 输入样例 2: 48 11 6 输出样例 2: No Solution 思路:1.丙的能力值有可能是小数因此要用double 首次通过代码: 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<math.h> 4 5 6 7 int main(){ 8 int m,x,y; 9 int flag=1; 10 s