www.etiger.vip DEVC + + Practice (Introduction)

Posted by jesirose on Tue, 08 Feb 2022 22:10:36 +0100

First question,

#Include < iostream > / / call out the streaming toolbox
using namespace std;   //Use normal namespace
int main(){            //Start main program
    long long a,b;     //Define integer variables a, b
    cin>>a;            //Enter and assign to integer variable a
    cin>>b;            //Enter and assign to integer variable b
    cout<<a+b;         //Sum of output a+b
    return 0;          //The main program ends and the program returns to 0
}


Title Description of the second question

Please write a program, input n different integers, delete the maximum number and the minimum number, and output the remaining n-2 integers in turn.

Input / output format

Input format
There are two lines for input: the first line is positive integer n, and the second line is n integers.
Where n < = 100, the absolute value of the number shall not exceed 100000.
Output format
There are n-2 integers in a row
Sample input and output
Input example 1:

5
10 8 5 2 6
Output example 1:

8 5 6

#include <bits/stdc++.h>
using namespace std;
int main(){
    int a;
    cin>>a;
    int arr[a];
    for(int i = 0;i<a;i++){
        cin>>arr[i];
    } 
    int Max = *max_element(arr,arr+a);
    int Min = *min_element(arr,arr+a);
    for(int i = 0;i<a;i++){
        if(arr[i]!=Max&&arr[i]!=Min){
            cout<<arr[i]<<" ";
        }
    }
    return 0;
}


Title Description of the third question

Input format
No input
Output format
Output lester handsome man
Sample input and output
Input example 1:

No input
Output example 1:

lester handsome

#include<iostream>
using namespace std;
int main(){
      cout<<"lester Handsome guy";
    return 0;
    //Too simple//
}


Title Description of question 4

Divide 9 numbers of 1, 2,..., 9 into three groups to form three three digits respectively, and make these three digits form a ratio of 1:2:3, and try to find all three three digits that meet the conditions

Input / output format

Input format
No input
Output format
Several lines, each with 3 numbers. Sort in ascending order according to the first number in each line

#include <bits/stdc++.h>
using namespace std;
int main(){
    for(int i = 123;i<=329;i++){
        int ling = 0,yi=0,er=0,san=0,si=0,wu=0,liu=0,qi=0,ba=0,jiu=0;
        int j = i*2;
        int m = i*3;
        if(i%10==1||i/10%10==1||i/100==1||j%10==1||j/10%10==1||j/100==1||m%10==1||m/10%10==1||m/100==1)yi = 1;
        if(i%10==2||i/10%10==2||i/100==2||j%10==2||j/10%10==2||j/100==2||m%10==2||m/10%10==2||m/100==2)er = 1;
        if(i%10==3||i/10%10==3||i/100==3||j%10==3||j/10%10==3||j/100==3||m%10==3||m/10%10==3||m/100==3)san = 1;
        if(i%10==4||i/10%10==4||i/100==4||j%10==4||j/10%10==4||j/100==4||m%10==4||m/10%10==4||m/100==4)si = 1;
        if(i%10==5||i/10%10==5||i/100==5||j%10==5||j/10%10==5||j/100==5||m%10==5||m/10%10==5||m/100==5)wu = 1;
        if(i%10==6||i/10%10==6||i/100==6||j%10==6||j/10%10==6||j/100==6||m%10==6||m/10%10==6||m/100==6)liu = 1;
        if(i%10==7||i/10%10==7||i/100==7||j%10==7||j/10%10==7||j/100==7||m%10==7||m/10%10==7||m/100==7)qi = 1;
        if(i%10==8||i/10%10==8||i/100==8||j%10==8||j/10%10==8||j/100==8||m%10==8||m/10%10==8||m/100==8)ba = 1;
        if(i%10==9||i/10%10==9||i/100==9||j%10==9||j/10%10==9||j/100==9||m%10==9||m/10%10==9||m/100==9)jiu = 1;
        if(yi==1&&er==1&&san==1&&si==1&&wu==1&&liu==1&&qi==1&&ba==1&&jiu==1){
            cout<<i<<" "<<j<<" "<<m<<endl;
        }
    }
    return 0;
} 



Question 5 5 Make peace

Title Description

There are n integers numbered from 1 to N. judge whether two numbers with different numbers can be found, and the sum is m.

If it can be found, the output is Yes. If not found, output No.  

Note: you need to find two numbers with different numbers.

Input / output format

Input format
The first line of input is n and m integers, and the second line is n numbers.
Where n < = 100, the absolute value of the number shall not exceed 100000.
Output format
Yes or No
Sample input and output
Input example 1:

4 15
1 5 3 10
Output example 1:

Yes

#include<bits/stdc++.h>
using namespace std;
int m,n,num[101],i,j;
bool ans=0; 
int main(){
    cin>>n>>m;
    for(i=0;i<n;i++)cin>>num[i];
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++)
            if(num[i]+num[j]==m){ans=1;break;}
    }
    cout<<(ans?"Yes":"No")<<endl;
    return 0;
}


6. Case conversion

Title Description

Converts uppercase letters to lowercase and lowercase letters to uppercase in a string

Input / output format

Input format
A line of string containing only letters, without checking the validity of the input
Output format
One line string
Input sample #1:

abcdEFG
Output example #1:

ABCDefg

#include<bits/stdc++.h>
using namespace std;
char c;
int main(){
    while(cin>>c){
        if(c>='A'&&c<='Z')cout<<char(c+32);
        if(c>='a'&&c<='z')cout<<char(c-32);
    }
    return 0;
}


7. Pass line

Title Description

The Chinese teacher's math is not very good. He is always wrong about whether the students Pass the exam. As a master programmer, you decided to help each other. If the student scores 60 points, he is qualified and should output Pass; Otherwise, Fail is output.

Input / output format

Input format
Enter a non negative integer to ensure that it does not exceed 100
Output format
Output Pass or Fail
Sample input and output
Input sample #1:

60
Output example #1:

Pass
Input sample #2:

59
Output example #2:

Fail

#include<iostream>
using namespace std;
int main(){
    int a;
    cin>>a;
    if(a>=60)
        cout<<"Pass";
    else
        cout<<"Fail";
    return 0;
}

7. A diamond

Title Description

Please write a program to use the output command to output a diamond on the plane. For the specific shape, please refer to the output example below.

be careful:

There are 3 lines in total, and each line has a new line, and there can be no extra empty lines between lines;

There should be no extra space after the asterisk at the end of the line;

There should be no spaces between asterisks.

Input / output format

Input format

nothing

Output format

a diamond 

Sample input and output

Input sample #1:

nothing

Output example #1:

 *
***
 *
#include<iostream>
using namespace std;
int main(){
	cout<<" *"<<endl;
	cout<<"***"<<endl;
	cout<<" *"<<endl;
	return 0;
}

8. Achievements

Title Description

Niuniu recently learned the C + + introductory course. The total score of this course is calculated as follows: total score = homework score × 20% + quiz results × 30% + final exam results × 50% of Niuniu want to know how many points they can finally get in this course.

Input / output format

Input format

1 line, including three non negative integers a, B and C, which represent Niuniu's homework scores, quiz scores and final examination scores respectively. A, B and C are all integer multiples of 10. Two adjacent numbers are separated by a space, and the full score of the three items is 100.

Output format

1 line, including an integer, that is, the total score of Niuniu is also 100.

Sample input and output

Input sample #1:

100 100 80

Output example #1:

90

Input sample #2:

60 90 80

Output example #2:

79
#Include < iostream > / / call out the streaming toolbox 
using namespace std;               //Use normal namespace 
int main(){                        //Start main program 
	long long a,b,c;               //Integer, a, B, variable definition 
	cin>>a>>b>>c;                  //Enter and assign to integer variable a 
	cout<<a*0.2+b*0.3+c*0.5;       //Output score 
	return 0;                      //The main program ends and the program returns to 0 
}

Question 8

63. Sandwich matching

Title Description

Sandwich kingdom is a new fast-food restaurant, specializing in sandwiches. A sandwich includes bread, meat dishes, vegetables and sauce. Fast food restaurants have a kind of bread, b kinds of meat dishes, c kinds of vegetables and 8 kinds of sauces. How many kinds of meals do customers choose?

Input / output format

Input format

Three integers, a, b, c, represent the type and quantity of bread, meat dishes and vegetables, a < = 10000, B < = 10000, C < = 10000

Output format

An integer indicating the number of choices the customer has made for ordering

Sample input and output

Input sample #1:

4 6 2

Output example #1:

384
//FA Yi//
#include<iostream>
using namespace std;
int main(){
	long long a,b,c,n;
	cin>>a;
	cin>>b;
	cin>>c;
	n=a*b*c*8;
	cout<<n;
	return 0;
}
//Method II//
#include<iostream>
using namespace std;
int main(){
	long long a,b,c,n;
	cin>>a;
	cin>>b;
	cin>>c;
	cout<<a*b*c*8;
	return 0;
}

New to CSDN, please give us more advice!

This article is updated every three days.

Follow + like more than 100 updates immediately!

Copyright notice: This is CSDN blogger "Ian 20124" If you need to reprint your original article, please inform CSDN blogger "Ian 20124".


---------------------—

Topics: C++