I would like to say that regardless of the algorithm selection requirements, this is a primary school math problem of finding . When inputting, check whether a and b are both odd or even numbers and whether the number is within the available range of the super variable type, and then you must also consider this issue in the case you generate
Using the materials you provided, I coded it in C++ as follows. I hope you can correct me!
/*
if Natalia's number of apples is x (x>0)
apples:the number of apple
extra:the number that Klaudia more tha Natalia
(apples>extra>0)
so
x+extra+x=apples
x = (apples-extra)/2
*/
#include <iostream>
int main(int argc, char const *argv[]) {
int apples,extra; //apples:the number of apple extra:the number that Klaudia more tha Natalia
for (size_t i = 0; i < 10; i++) {
std::cin>>apples>>extra; //input
try{
//To determine whether the input is legal
if(apples<=0 || extra<=0 || apples<extra || (apples-extra)%2!=0) throw apples;
int Klaudia,Natalia;
Natalia = (apples-extra)/2; //calculate
Klaudia=Natalia+2;
std::cout<<Klaudia<<'\n'<<Natalia<<'\n'; //output
}
catch(int e){
//ERROR
std::cerr << "ERROR! the number of applse is error.\n" << '\n';
}
}
return 0;
}
I would like to say that regardless of the algorithm selection requirements, this is a primary school math problem of finding .
When inputting, check whether a and b are both odd or even numbers and whether the number is within the available range of the super variable type, and then you must also consider this issue in the case you generate
Using the materials you provided, I coded it in C++ as follows. I hope you can correct me!
Run results