Blue Bridge Cup Official Website Question Bank [Simple Question Analysis] Continuously updated

table of Contents

Word analysis

https://www.lanqiao.cn/problems/504/learning/

  • Title description
    Xiaolan is learning a magical language. The words in this language are made up of lowercase English letters. Some words are very long, far exceeding the length of normal English words. Xiaolan had been learning for a long time and couldn't remember some words. He planned not to remember these words completely, but to distinguish words based on which letter appeared the most.
    Now, please help Xiaolan. After giving a word, help him find the most frequent letter and the number of times this letter appears.
  • Input description The
    input line contains one word, and the word only consists of lowercase English letters.
    For all evaluation cases, the input word length should not exceed 1000.
  • Output description
    Output two lines. The first line contains an English letter, which indicates which letter appears most frequently in a word. If there are multiple letters that appear the same number of times, the one with the smallest lexicographic order is output.
    The second line contains an integer that represents the number of times the most frequent letter appears in the word.
  • Sample input and output
示例 1
输入
lanqiao
输出
a
2

示例 2
输入
longlonglongistoolong
输出
o
6

Problem analysis: Use hash addressing method. That is, the number of statistics corresponding to the array subscript

#include <iostream>
# include <bits/stdc++.h>
using namespace std;
int c[26];
int main()
{
    
    
  string a;
  cin>>a;int max=0;
  int i;int b=97;char x;
  for(i=0;i<a.length();++i)
  {
    
    
    ++c[a[i]-97];
  }
  for(i=0;i<26;++i)
  {
    
    
    if(c[i]>max){
    
    
      max=c[i];
      x=i+97;
    }
  }
  cout<<x<<endl<<max<<endl;
  return 0;
}

Stupid kid

https://www.lanqiao.cn/problems/527/learning/

  • Title description The
    stupid monkey has a very small vocabulary, so every time he does English multiple-choice questions, he has a headache. But he found a way, and the experiment proved that when using this method to choose the option, the chance of choosing the right option is very high!
    The specific description of this method is as follows: Suppose maxnmaxn is the number of occurrences of the letter with the most occurrences in a word, minnminn is the number of occurrences of the letter with the least occurrences in the word, if maxn-minnmaxn−minn is a prime number, then the dumb monkey is Think this is a Lucky Word, such a word is probably the correct answer.
  • Enter description
    Enter a line, which is a word, in which only lowercase letters may appear, and the length is less than 100.
  • Output description
    Output two lines, the first line is a string, if the input word is Lucky Word, then output Lucky Word, otherwise output No Answer; the
    second line is an integer, if the input word is Lucky Word, output maxn- The value of minnmaxn−minn, otherwise 0 is output.
  • Sample input and output
示例 1
输入
error
copy
输出
Lucky Word
2

示例 2
输入
Olympic
copy
输出
No Answer
0

Analysis of this question:
1. Count the number of each character (using the hash addressing method, that is, the array subscript to count)
2. Find the most frequent and the least frequent
3. Judgment of prime numbers

#include <iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
char str[105];
int a[27]={
    
    0};
int main()
{
    
    
  // 请在此输入您的代码
  gets(str);
  int max=-1;
  int min=1000;
  int number=0;
  int i,j;
  int flag=0;
  for(i=0;i<strlen(str);i++)
  {
    
    
      if(str[i]>='a')
      {
    
    
         a[str[i]-'a']++;
      }
  }
  for(i=0;i<26;i++)
  {
    
    
     if(a[i]>max)
      max=a[i];
    if(a[i]<min&&a[i]>0)
      min=a[i];
  }
  number=max-min;
  for(i=2;i<sqrt(number);i++)
  {
    
    
      if(number%i==0)//不是质数
      {
    
    
        flag=1;//用来标志不是质数
        break;
      }
  }
  if(number==0||number==1)//排除一些特殊的情况
  {
    
    
    printf("No Answer\n0");
    return 0;
  }
  if(!flag)
  {
    
    
      printf("Lucky Word\n");
  }
  else
  {
    
    
     printf("No Answer\n0");
     return 0;
  }
  printf("%d\n",number);
  return 0;
}

Guess you like

Origin blog.csdn.net/qq_46527915/article/details/114777403
Recommended