#include <iostream>
#include <string>
#include <sstream>
using namespace std;
template <typename T>
std::string toString(T val)
{
std::ostringstream oss;
oss<< val;
return oss.str();
}
template<typename T>
T fromString(const std::string& s)
std::istringstream iss(s);
T res;
iss >> res;
return res;
int main()
string number;
short int param;
cin >> param;
char i1,i2,i3,i4,i5,i6;
long long i,counter;
counter =0;
for(i=100000;i<=999999;i++){
number= toString(i);
i1 = number[0] ;
i2 = number[1] ;
i3 = number[2] ;
i4 = number[3] ;
i5 = number[4];
i6 = number[5];
if((i1+i2+i3) == (i4+i5+i6) && (i4+i5+i6) == param) {
cout << i1+i2+i3 <<" = "<<i4+i5+i6<<endl;
counter++;}
cout << counter;
return 0;
Объяснение:
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
template <typename T>
std::string toString(T val)
{
std::ostringstream oss;
oss<< val;
return oss.str();
}
template<typename T>
T fromString(const std::string& s)
{
std::istringstream iss(s);
T res;
iss >> res;
return res;
}
int main()
{
string number;
short int param;
cin >> param;
char i1,i2,i3,i4,i5,i6;
long long i,counter;
counter =0;
for(i=100000;i<=999999;i++){
number= toString(i);
i1 = number[0] ;
i2 = number[1] ;
i3 = number[2] ;
i4 = number[3] ;
i5 = number[4];
i6 = number[5];
if((i1+i2+i3) == (i4+i5+i6) && (i4+i5+i6) == param) {
cout << i1+i2+i3 <<" = "<<i4+i5+i6<<endl;
counter++;}
}
cout << counter;
return 0;
}
Объяснение: