Skip to content

Instantly share code, notes, and snippets.

@olecksamdr
Created October 21, 2016 06:20
Show Gist options
  • Save olecksamdr/0f68ec1e09ea9c20f44586cff7ca36b1 to your computer and use it in GitHub Desktop.
Save olecksamdr/0f68ec1e09ea9c20f44586cff7ca36b1 to your computer and use it in GitHub Desktop.
// 2.2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
#include <cstdlib>
#include <algorithm>
using namespace std;
string to_string(int number)
{
string str = "";
while (number) {
str += (char)('0' + number % 10);
number /= 10;
}
reverse(str.begin(), str.end());
return str;
}
int to_int (string str) {
int result = str[0] - '0';
for (int i = 1; i < str.length(); i++) {
result += (str[i] - '0') * 10 ;
}
return result;
}
int from_A_to_B(int A, int B) {
string result = to_string(A);
for (int i = A + 1; i <= B; i++){
result += to_string(i);
}
return to_int(result);
}
string sfrom_A_to_B(int A, int B) {
string result = to_string(A);
for (int i = A + 1; i <= B; i++){
cout << "to_string(i): " << to_string(i) << endl;
result += to_string(i);
}
return result;
}
int _tmain(int argc, _TCHAR* argv[])
{
int A;
int C;
cout << sfrom_A_to_B(1, 10) << endl;
cout << from_A_to_B(1, 10) << endl;
cout << "Write number A: ";
cin >> A;
cout << endl;
cout << "Write number C: ";
cin >> C;
cout << endl;
int B = A + 1;
int AB = from_A_to_B(A, B);
while (AB % C != 0) {
B++;
AB = from_A_to_B(A, B);
}
cout << "B is: " << B << endl;
cout << "AB is: " << AB << endl;
int a;
cin >> a;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment