The end of the SPOC programming questions of Huazhong University of Science and Technology (Autumn 2020)

1 Calculate the time required for the journey (20 minutes)
Question content:

Give the departure time of the train in one line, and enter the number of days of arrival and the time of arrival after the line break, separated by spaces. If the train arrives on the same day, the number of days is 0, the number of days that arrive the next day is 1, and so on. Departure time and arrival time are represented by a 4-digit integer, the upper 2 digits are 2 digits for hours (00-23), and the lower 2 digits are 2 digits for minutes (00-59). If the high digit is 0, do not enter.

Input format:

Enter the departure time on the first line

Enter the number of days of arrival in the second line, and enter the arrival time after one blank

Output format:

Output the time hours and minutes required for the entire journey . If it is less than 1 hour, only the minute is displayed. If it is an integer hour, only the hour is displayed.

Input sample:

1700

1 915

Sample output:

16 hours 15 minutes

Input sample:

30

0 1915

Sample output:

18 hours 45 minutes

Time limit: 500ms Memory limit: 32000kb

#include <iostream>
#include <cmath>
using namespace std;


 int main()

 {
    
    
	 int s=0,e=0,d=0,h=0,m=0;
	 int i=0,j=0,sum=0;
	 cin>>s;
	 cin>>d;
	 cin>>e;
	 int s1=s,e1=e;
	 int h1=0,h2=0,m1=0,m2=0;
	 for(i=0;i<2;i++)
	 {
    
    m1=(s1%10)*pow((double)10,i)+m1;
	 s1=s1/10;
	 }
	 	 for(i=0;i<2;i++)
	 {
    
    h1=(s1%10)*pow((double)10,i)+h1;
	 s1=s1/10;
	 }
			 for(i=0;i<2;i++)
	 {
    
    m2=(e1%10)*pow((double)10,i)+m2;
	 e1=e1/10;
	 }
			 	 for(i=0;i<2;i++)
	 {
    
    h2=(e1%10)*pow((double)10,i)+h2;
	 e1=e1/10;
	 }
				
	m=m2-m1;h=h2-h1;
	h=h+24*d;
	 if(m<0)
	 {
    
    
		 m=m+60;h=h-1;
	 }
	 if(h==0)
	 {
    
    
cout<<m<<"分钟"<<endl;j=1;
	 }
	 
	 if(m==0)
	 {
    
    cout<<h<<"小时"<<endl;j=1;
	 }
	 if(j==0)
	 cout<<h<<"小时"<<m<<"分钟"<<endl;
	 return 0;
 }

2Natural number representation (20 points)
topic content:

Input a natural number less than 1000, express it as the sum of continuous natural numbers, and output all the expressions.

For example: 9=2+3+4=4+5

If the natural number cannot be expressed as the sum of continuous natural numbers, then output its own value.

For example: 1=1, 8=8

Input format: input a natural number (a positive integer less than 1000)

Output format: output all the sums it can express (addends from small to large)

Input sample: 21

Sample output:

21=1+2+3+4+5+6

21=6+7+8

21=10+11

Input sample:

1

Sample output:

1=1

Time limit: 500ms Memory limit: 32000kb

#include <iostream>
using namespace std;
int main()
{
    
    
	int n,i,j,sum=0,flag=1;
	cin>>n;
    for(i=1;i<=n;i++)
	{
    
    
		sum=0;
		for(j=i;j<n;j++)
		{
    
    
			sum=sum+j;
			if(sum==n)
			{
    
    
				flag=0;
				cout<<n<<"=";
				for(int k=i;k<j;k++)
					cout<<k<<"+";
				cout<<j<<endl;
				
				break;
			}
			if(sum>n)
			{
    
    
				break;
			}
			else
				continue;
		}
	}
	if(flag)
		cout<<n<<"="<<n<<endl;
	return 0;
}

3 Find the highest score and number (20 points)
content of the question:

There are 10 students whose names are: Zhang Hong, Wang Li, Li Ming, Wang Ming, Liu Shaoyang, Liu Mingyang, Ouyang Shaoyang, Li Li, Li Li, Ou Ming. The numbers are integers from 1 to 10. Enter the C++ course test scores of these 10 students in turn, output the highest score, the number of students with the highest score, and the number and name of the highest score student. If multiple students get the highest score, all output is required.

Note: In order to prevent scoring errors caused by missing Chinese and English symbols and characters, please copy Chinese characters and punctuation marks from the output sample when writing output sentences.

Input format:

Enter the grades of 10 students in turn

Output format:

Input sample:

99 98 97 100 96 95 94 100 93 100

Output sample: Note that there are 2 English spaces between the data.

Maximum score is 100

3 people got the highest score

The number and name of the student with the highest score are:

4 Wang Ming

8 Li Li

10 Ou Ming

Time limit: 500ms Memory limit: 32000kb

#include <iostream>
using namespace std;
double max(double a[],int n)
{
    
    
	int m=a[0];
	for(int i=0;i<n;i++)
	{
    
    
		if(a[i]>m)
			m=a[i];
	}
	return m;
}
double num(double a[],int n,double m)
{
    
    
	int p=0;
	for(int i=0;i<n;i++)
	{
    
    
		if(a[i]==m)
			p++;
	}
	return p;
}
int main()
{
    
    
	double a[10];
	for(int i=0;i<10;i++)
	{
    
    
		cin>>a[i];
	}
	char b[10][20]={
    
    "张红","王丽","李明","王明","刘少阳","刘明洋","欧阳少阳","李丽","李莉","欧明"};
	cout<<"最高分为"<<max(a,10)<<endl;
	cout<<"获得最高分的共有"<<num(a,10,max(a,10))<<"人"<<endl;
	cout<<"获得最高分的同学编号和姓名为:"<<endl;
	for(int i=0;i<10;i++)
	{
    
    
		if(a[i]==max(a,10))
		{
    
    
			cout<<i+1<<"  "<<b[i]<<endl;
		}
	}
	return 0;
}

4 Find the check code of the book ISBN (20 points)
title content:

Every officially published book has an ISBN number corresponding to it. The ISBN code includes 9 digits, 1 digit identification code and 3 digits separator. Its prescribed format is as follows: "x-xxx-xxxxx-x", where the symbol "-" is the separator (the minus sign on the keyboard), and the last digit is the identification code. For example, "1-673-82169-3" is a standard ISBN code.

The first digit of the ISBN code indicates the publication language of the book, for example, the symbol "1" represents mathematics; the three digits after the first separator "-" represent the publisher code, and the five digits after the second separator "82169" "Represents the serial number of the book in the publisher; the calculation method of the last digit of the identification code:

1. The first digit is multiplied by 1, plus the second digit is multiplied by 2, and the third digit is multiplied by 3,..., and so on;

2. Then calculate the remainder of the result to 11, and the obtained remainder is the identification code. If the remainder is 10, the identification code is a capital letter X.

Code: (write function ISBN, perfect the following code)

#include
#include
using namespace std;
int main()
{
char charISBN11[12], charISBN[14],*ch;
cin>>charISBN11;
ch=ISBN(charISBN11,charISBN);
cout<<ch<<endl;
return 0;
}输入格式:

Enter the first 11 characters of the ISBN

Output format:

Output the complete ISBN code.

Input sample:

1-673-82169

Sample output:

1-673-82169-3

Time limit: 500ms Memory limit: 32000kb

#include <iostream>

#include <cstring>

using namespace std;

char * ISBN(char m[])
{
    
    int sum=0,i=0,j,n=1;
	for(i=0;i<11;i++)
	{
    
    
		if(m[i]=='-')
		continue;
		j=m[i];
		j=j-48;
		sum=n*j+sum;n++;
	}
	j=sum%11;
	char *a=new char[100];
	for(i=0;i<11;i++)
		a[i]=m[i];
	if(j==10)
	{
    
    a[11]='-';a[12]='X';a[13]='\0';}
	else
	{
    
    a[11]='-';a[12]=(char)(sum%11+'0');a[13]='\0';}

	
	return a;

}
int main()

{
    
    
    char charISBN11[12], *charISBN;

    cin>>charISBN11;

    charISBN=ISBN(charISBN11);

    cout<<charISBN<<endl;

    delete charISBN;

	getchar();
    return 0;

}

5 Realize related operations of string class (20 points)
Topic content: Define a string class Cstring, which is required to realize the copy of string, find the length of the string, compare the size of two strings, and find the specification of the string The length of the left substring and the specified length of the right substring.

The main function is as follows, please add the definition of the cstring class to complete the program.

int main()
{ cstring s1(“abcdef”),s2;
char ch[200];
cin.getline(ch,200);
s2.init(ch);
cout<<s1.compare(s2)<<endl;
cout<<s1.length()<<endl;
cout<<s2.length()<<endl;
s1.copy(s2);
cout<<s1.compare(s2)<<endl;
cout<<s1.length()<<endl;
cout<<s2.length()<<endl;
s1.disp();
s2.disp();
char x[10],y[10];
s1.left(x,3);
s1.right(y,4);
cout<<x<<endl;
cout<<y<<endl;
return 0;
}

Input format:

Enter a string

Output format:

Input sample:

abcdefgh

Sample output:

-103

6

8

0

8

8

abcdefgh

abcdefgh

abc

hgfe

Time limit: 500ms Memory limit: 32000kb

#include <iostream>
#include <cmath>
#include<cstring>
using namespace std;
class cstring
{
    
    private:
char c[200];
public:
	cstring(){
    
    ;}
	cstring(char a[]){
    
    strcpy(c,a); }
	void init(char b[]){
    
    strcpy(c,b); }
	int compare(cstring d){
    
     
		int i=0;int m=0;
	while(c[i]!=0&&d.c[i]!=0)
	{
    
    
		
		if(d.c[i]==c[i])
			i++;
		else break;
		
	}
		 m=-d.c[i]+c[i]; return m;
	}
	int length(){
    
    return strlen(c);}
	void copy(cstring e){
    
     strcpy(c,e.c);}
	void disp(){
    
    cout<<c<<endl;}
	void left(char m[],int n){
    
     
		for(int i=0;i<n;i++)
			m[i]=c[i];
		m[n]=0;
	}
	void right(char u[],int o)
	{
    
    int l=strlen(c);
		for(int i=0;i<o;i++)
			u[i]=c[l-1-i];
		u[o]=0;
		
	}
};


int main()
 {
    
     cstring  s1("abcdef"),s2;
  char ch[200];
  cin.getline(ch,200);
  s2.init(ch);
  cout<<s1.compare(s2)<<endl;
  cout<<s1.length()<<endl;
  cout<<s2.length()<<endl;
  s1.copy(s2);
  cout<<s1.compare(s2)<<endl;
  cout<<s1.length()<<endl;
  cout<<s2.length()<<endl;
  s1.disp();
  s2.disp();
  char x[10],y[10];
  s1.left(x,3);
  s1.right(y,4);
  cout<<x<<endl;
  cout<<y<<endl;
  return 0;
 }

Guess you like

Origin blog.csdn.net/weixin_51236357/article/details/112408043