#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;
Объяснение:
setlocale(LC_ALL, "Russian");
int arr_pattern[5] = { 1,3,3,2,2 };
int temp = 0;
string arr_temp[4] = { "(",")-","-","-" };
size_t j = 0;
string arr_str[5];
string str;
cout << "Введите номер телефона: ";
cin >> str;
for (size_t i = 0; i < sizeof(arr_pattern) / sizeof(arr_pattern[0]); i++) {
arr_str[i] = str.substr(0, arr_pattern[i]);
str.erase(0, arr_pattern[i]);
cout << str << endl;
for (size_t i = 0; i < 5; i++)
if (i == 4) {
cout << arr_str[i];
else {
cout << arr_str[i] << arr_temp[j];
j++;
#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>
using namespace std;
int main()
{
setlocale(LC_ALL, "Russian");
int arr_pattern[5] = { 1,3,3,2,2 };
int temp = 0;
string arr_temp[4] = { "(",")-","-","-" };
size_t j = 0;
string arr_str[5];
string str;
cout << "Введите номер телефона: ";
cin >> str;
for (size_t i = 0; i < sizeof(arr_pattern) / sizeof(arr_pattern[0]); i++) {
arr_str[i] = str.substr(0, arr_pattern[i]);
str.erase(0, arr_pattern[i]);
}
cout << str << endl;
for (size_t i = 0; i < 5; i++)
{
if (i == 4) {
cout << arr_str[i];
}
else {
cout << arr_str[i] << arr_temp[j];
j++;
}
}
}