Nanxin 2018-2020 822 real question answers (hand notes)

When doing the real question, I wrote down the answer by the way, too lazy to verify whether it is correct or not, let's check the correct answer, please advise if there is a problem. By the way, the link to the actual question is here. Nanxin 822 historical question

2020 822 real question answer

Multiple choice

  1. B
  2. C
  3. D
  4. C
  5. C
  6. D
  7. D
  8. AC
  9. C
  10. A
  11. B

Fill in the blank

  1. ASCLL code
  2. String
  3. Letter underline
  4. 8 bytes
  5. NULL

Fill in the blanks

  1. Receive keyboard input, until press Enter, if there is more than one continuous space, only one space will be output
 #include <stdio.h>
 int main()
 {
    
    
    char cx, front='\0';
	while((cx=getchar())!='\n')
	{
    
    
		if(cx!=' ') putchar(cx);
		if(cx==' ')
			if(front!=cx)
				putchar(cx);
		front=cx;
	}
    return 0;
 }
  1. A two-dimensional matrix that outputs the sum of surrounding elements
#include <stdio.h>
#define N 3
int main()
{
    
    
	int a[N][N];
	int i,j,sum=0;
	for(i=0;i<N;i++)
		for(j=0;j<N;j++)
			scanf("%d",&a[i][j]);
	printf("矩阵:\n");
	for(i=0;i<N;i++)
	{
    
    
		for(j=0;j<N;j++)
			printf("%4d",a[i][j]);
		putchar(10);		
	}
	for(i=0;i<N;i++)
		for(j=0;j<N;j++)
			if(i==0 || j==0 || i==N-1 || j==N-1)
				sum+=a[i][j];		
	printf("\n矩阵周边和为:%d\n",sum);
    return 0;
}

  1. Find the middle of the three numbers
#include <stdio.h>
int main()
{
    
    
	int a,b,c,t;
	scanf("%d %d %d",&a,&b,&c);
	if(a>b){
    
    t=a;a=b;b=t;}
	if(a>c){
    
    t=a;a=c;c=t;}
	if(b>c){
    
    t=b;b=c;c=t;}
	printf("中间数为:%d\n",b);
	return 0;
}

Programming questions

  1. Find the number of palindromes
#include <stdio.h>
int main()
{
    
    
	long a,n,m=0;
	int i;
	scanf("%ld",&a);
	n=a;
	while(n)
	{
    
    
		i=n%10;
		m=m*10+i;
		n/=10;
	}
	if(m==a)
		printf("%ld是回文数!\n",a);
	else 
		printf("%ld不是回文数\n",a);
	return 0;
}

  1. Find the number of substrings from the parent string
#include <stdio.h>
#include <string.h>
int count(char [],char []);
int main()
{
    
    
	char a[80],b[10];
	int k;
	gets(a);
	gets(b);
	k=count(a,b);
	if(k==0)
		printf("没有找到!\n");
	else
		printf("%d\n",k);
	return 0;
}
int count(char s[],char t[])
{
    
    
	int i,j,k,m=0;
	for(i=0;s[i]!='\0';i++)
	{
    
    
		k=0;
		for(j=i;s[j]==t[k]&&k<strlen(t);j++)
			k++;
		if(t[k]=='\0')
			m++;
	}
	return m;
}

  1. Enter the data of 8 students from the structure. The student data includes student ID and grade. Write a function to store the student data above the average score in a new array. The function returns the student’s average score, which is higher than the average score. The number of students is returned by the formal parameter n
#include <stdio.h>
#include <string.h>
#define N 8
typedef struct Student
{
    
    
	char num[6];
	float score;
}STU;
void input(STU [],int);
void output(STU [],int);
float avg(STU [],STU [],int,int *);
int main()
{
    
    
	STU stu[N],newstu[N];
	int n=0;
	float aver;
	input(stu,N);
	putchar(10);
	output(stu,N);
	aver=avg(stu,newstu,N,&n);
	printf("\n高于平均分的人有:\n");
	output(newstu,n);
	return 0;
}
void input(STU s[],int n)
{
    
    
	int i;
	for(i=0;i<n;i++)
		scanf("%s %f",s[i].num,&s[i].score);
}
void output(STU s[],int n)
{
    
    
	int i;
	for(i=0;i<n;i++)
	{
    
    
		printf("%8s %7.2f\n",s[i].num,s[i].score);
		
	}
}
float avg(STU s[],STU newstu[],int m,int *n)
{
    
    
	int i,j=0;
	float sum=0,avg;
	for(i=0;i<m;i++)
		sum+=s[i].score;
	avg=sum/N;
	for(i=0;i<m;i++)
		if(s[i].score>avg)
		{
    
    
			strcpy(newstu[j].num,s[i].num);
			newstu[j].score=s[i].score;
			j++;
			*n=*n+1;
		}
	return avg;
}

2019 822 real question answer

Multiple choice

  1. D
  2. D
  3. C
  4. D
  5. A
  6. D
  7. C
  8. C

fill in the blank

  1. 1
  2. 26
  3. sqrt(fabs(a-b))/3*(a+b)
  4. sqrt((xx+yy)/(a+b))
  5. Global variable local variable static momentum dynamic momentum
  6. Nested recursion
  7. 8
  8. 12

Program reading

  1. Only one question is the same as in 2020

Programming questions

  1. As in 2020, the core part is given here
int count(char *str,char *substr)
{
    
    
	int i,j,k,num=0;
	for(i=0;i<strlen(str);i++)
		for(j=i,k=0;str[j]==substr[k];j++,k++)
		    if(substr[k+1]=='\0'){
    
    
			    num++;
                break;
            }
	return num;
}
  1. Design a program to make an array 7849846 flashback output
#include <stdio.h>
#define N 7
int main()
{
    
    
    int a[N];
    int i;
    for(i=0;i<N;i++)
        scanf("%d",&a[i]);
    for(i=N-1;i>=0;i--)
        printf("%d",a[i]);

}
  1. 10 classmates have name numbers, three lesson scores, a function is designed to return the name of the student with the best score, and output the average score of the three subjects
    (the original question in the book is omitted )

2018 822 real question answer

Multiple choice

  1. B
  2. C
  3. A
  4. C
  5. D
  6. C
  7. B
  8. C
  9. C
  10. B
  11. A
  12. B
  13. B
  14. B
  15. D
  16. B
  17. C
  18. A
  19. AC
  20. A

Fill in the blanks

  1. function
  2. 0
  3. This layer
  4. 2
  5. do-while
  6. a+6
  7. Constant value address value
  8. Text file binary file

Procedural reading questions

  1. 2 1

  2. 123.1415926

  3. 1 2 4 8

  4. 9

  5. a=10,b=10

    a=10,b=20

  6. 4

  7. 7
    5

  8. 1 1 2 3
    5 8 13 21
    34 55 89 144

Fill in the blanks

  1. (1) int,int
    (2) product(a,b)
    (2) return mul
  2. (1) i/100
    (2) i/10%10
    (3) i%10
  3. (7) p=p*n
  4. (8) n%i==0
    (9) a[j++]=i
  5. (10) (struct Node*)malloc(sizeof(struct Node))
    (11) q=q->next
    (12) head
  6. (13) i=0
    (14) k%i0 && k%20
    (15) j-1

Programming questions

The neck hurts so much I don’t want to write anymore. For the answers to the programming questions, please see the big guys below. Don’t want to repeat it.
Click to view the Nanxin 822 programming questions and answers

Guess you like

Origin blog.csdn.net/weixin_43983268/article/details/111564613