Chapter 3 Enumeration and Unit Conversion

Table of contents

Question 1 ASC

The second question space

Question 3: Number of approximations

Question 4 Word Analysis

Question 5: Reduced Fractions 

Question 6 Time display

Question 7 Special Time

Question 8: Multiply


Question 1 ASC

This question is a fill-in-the-blank question. You only need to calculate the result and use the output statement in the code to output the filled-in result.

It is known that the ASCII code of the capital letter A is 65. What is the ASCII code of the capital letter L?

operating restrictions

  • Maximum running time: 1s
  • Maximum running memory: 128M
  • #include <iostream>
    using namespace std;
    int main()
    {
      printf("%d",'L');
      return 0;
    }
    
    

    other:

  • #include<iostream>
    using namespace std;
    int main(){
    	printf("%d\n",'L');
    	for(int i='A';i<='Z';i++){
    		printf("%c:%d\n",i,i);
    	}
    	for (int i='a';i<='z';i++){
    		printf("%c:%d\n",i,i);
    	}
    	for (int i=91;i<=97;i++){
    		printf("%d:%c\n",i,i);
    	}
    	return 1; 
    } 

    A=65,a=97

The second question space

This question is a fill-in-the-blank question. You only need to calculate the result and use the output statement in the code to output the filled-in result.

Xiaolan plans to use 256MB of memory space to open an array. Each element of the array is a 3232-bit binary integer. If the space occupied by the program and the auxiliary space required for memory maintenance are not considered, how many 3232-bit binary integers can be stored in 256MB of space? Integer?

operating restrictions

  • Maximum running time: 1s
  • Maximum running memory: 128M

#include <iostream>
using namespace std;
int main()
{

  int m = 256;
  m = m *1024*1024*8.0/32.0;
  cout <<m;
  return 0;
}

Question 3: Number of approximations

This question is a fill-in-the-blank question. You only need to calculate the result and use the output statement in the code to output the filled-in result.

How many divisors does 12000001200000 have (only positive divisors are counted).

operating restrictions

  • Maximum running time: 1s
  • Maximum running memory: 128M

#include <iostream>
using namespace std;
int main()
{
  int cnt = 0;
  for (int i=1;i<=1200000;i++)
  {
  	if (1200000%i==0){
  		cnt++;
	  }
   } 
  cout <<cnt<<endl;
  return 0;
}

.

Question 4 Word Analysis

Question description

Xiaolan is learning a magical language. The words in this language are all composed of lowercase English letters. Some words are very long, far exceeding the length of normal English words. Xiao Lan couldn't remember some words after learning them for a long time. He was going to stop memorizing the words completely and instead distinguish the words according to which letters appeared most in the words.

Now, please help Xiaolan. After giving him a word, help him find the letter that appears the most and the number of times this letter appears.

Enter description

Enter a line containing a word consisting only of lowercase English letters.

For all evaluation cases, the input word length does not exceed 1000.

Output description

Output two lines. The first line contains an English letter, indicating which letter appears most frequently in the word. If there are multiple letters appearing the same number of times, output the one with the smallest lexicographic order.

The second line contains an integer representing the number of times the most common letter appears in the word.

Input and output samples

Example 1

enter

lanqiao

output

a
2

Example 2

enter

longlonglongistoolong

output

o
6

operating restrictions

  • Maximum running time: 1s
  • Maximum running memory: 256M

  

#include <iostream>
using namespace std;
string s;
int num[27];
int main()
{
  cin >>s;
  int max = 0;
  for (int i=0;i<s.length();i++)
    num[s[i]-'a']++;
  char ans;
  for (int i =0;i<27;i++)
    {
      if (num[i]>max)
        max = num[i],ans = i+'a';
    }
    cout <<ans <<endl<<max<<endl;
  return 0;
}

Global variables, arrays are initialized to 0 by default.

Question 5: Reduced Fractions 

Question description

This question is a fill-in-the-blank question. You only need to calculate the result and use the output statement in the code to output the filled-in result.

A fraction is called a reduced fraction if the greatest common divisor of its numerator and denominator is 11.

For example, \frac{3}{4} ,\frac{1}{8} ,\frac{7}{1}43​,81​,17​ are all reduced fractions.

How many reduced fractions are there where both the numerator and the denominator are integers between 11 and 20202020 (including 11 and 20202020)?

operating restrictions

  • Maximum running time: 2s
  • Maximum running memory: 128M

#include <iostream>
using namespace std;
string s;
int num[27];
int gcd(int i,int j){
	if (j==0) return i;
	else 
		return gcd(j,i%j);
}
int main()
{
	int ans = 0;
	for (int i=1;i<=2020;i++)
		for(int j=1;j<=2020;j++)
			if(gcd(i,j)==1) ans ++;
	cout <<ans<<endl;
  return 0;
}

Or __gcd(i,j)==1, a function that comes with the C language.

Euclid gcd, euclidean division method

 

Question 6 Time display

Output description

HH:MM:SSOutput the current time represented by hours, minutes and seconds , in  the format:  HH hours, values ​​range from 00 to 2323, MM minutes, values ​​from 00 to 5959, SS seconds, It ranges from 00 to 5959. If there are less than two digits in hours, minutes or seconds, add leading 00.

Input and output samples

Example 1

enter

46800999

output

13:00:00

Example 2

enter

1618708103123

output

01:08:23

Evaluation use case scale and conventions

For all evaluation cases, the given time is a positive integer not exceeding 10^{18}1018.

operating restrictions

  • Maximum running time: 1s
  • Maximum running memory: 512M
#include <iostream>
using namespace std;
typedef long long LL;
int main(){
	LL n;
	cin >>n;
	n /= 1000;
	n %= 60*60*24;
	printf("%02d:",n/60/60);
	n%=60*60;
	printf("%02d:",n/60);
	n%=60;
	printf("%02d\n",n ) ; 
	return 0;
} 

%02d, occupies two positions, if insufficient, use 0 to supplement it.

Question 7 Special Time

Problem Description

This question is a fill-in-the-blank question. You only need to calculate the result and use the output statement in the code to output the filled-in result.

February 22, 2022 22:20 2022:20 is a very meaningful time. The year is 2022, which is composed of 3 2s and 1 0. If the month and day are written as 4 digits, it is 0222, which is also composed of 3 2s. and 1 0. If the hours and minutes in time are written as 4 digits, they still consist of 3 2s and 1 0.

Xiaolan was very interested in such times. He also found other similar examples, such as October 11, 111, 01:11, 220201:11, February 22, 2202, 22:0222:02, and so on.

Please tell me, how many times are there in total where the year is written in 4 digits, the month and day are written in 4 digits, and the time is written in 4 digits and is composed of 3 numbers of one kind and 1 number of another kind. Note that November 11, 1111 11:1111:11 does not count because it does not contain two numbers.

operating restrictions

  • Maximum running time: 1s
  • Maximum running memory: 512Mz`         
#include <iostream>
using namespace std;
int main()
{
  int res = 0;
  for (int u=0;u<=9;++u) //出现一次的
    for (int v=0;v<=9;++v) //出现三次的
    {
      if(u==v)   //如果相同则跳过
        continue;
      int a=0,b=0,c=0;  //a 年     b 月日      c时分
      for(int pos = 0;pos<4;++pos){
        int nums[4];
        for (int i=0;i<4;++i) //不同位置的可能
          if (i==pos)
            nums[i] = u;
          else
            nums[i] = v;
        int y = nums[0]*1000+nums[1]*100+nums[2]*10+nums[3];
        a++;
        int m = y/100,d=y%100;
        if(m>=1 && m<= 12 && d>=1 && d<=30)
          b++;
        if(m>=0 && m<= 23 && d>=0 && d<=59)
          c++;
      }
      res +=a*b*c;
    }
  cout <<res <<endl;
  // 请在此输入您的代码
  return 0;
}

Question 8: Multiply

This question is a fill-in-the-blank question. You only need to calculate the result and use the output statement in the code to output the filled-in result.  Xiao Lan discovered that he would get different numbers by multiplying different numbers between 11 and 10000000071000000007 with 20212021 and then finding the remainder after dividing by 10000000071000000007. Xiao Lan wants to know if he can find a number between 11 and 10000000071000000007. After multiplying it with 20212021 and dividing it by 10000000071000000007, the remainder will be 999999999999999999. If it exists, please submit this number in your answer; if it does not exist, please submit 00 in your answer.

operating restrictions

  • Maximum running time: 1s
  • Maximum running memory: 128M
#include <iostream>
using namespace std;
typedef long long LL;

int main()
{
  for (LL i = 1;i<=1000000007;i++){
    if ((i*2021)%1000000007==999999999){
      cout << i<<endl;
      return 0;
    }
  }
  cout << 0 <<endl;
  // 请在此输入您的代码
  return 0;
}

#include  <climits>

cout << LONG_LONG_MAX<<endl;//Output the maximum range of longlong

cout << INT_MAX << endl;//The maximum range of int

Guess you like

Origin blog.csdn.net/lishijie258/article/details/128570160