~cpp
#include <iostream>
#include <conio.h>
using namespace std;
const int TRUE=1;
const int FALSE=0;
const int ENTER=13;
const unsigned __int64 MAX_LONG=1000000000000000000;
class save_number{
private:
unsigned __int64 number;
save_number *next;
save_number *prv;
public:
save_number(int input_number, save_number *who_next)
{
number=input_number;
next=who_next;
prv=NULL;
if (NULL!=who_next)
who_next->link(this);
}
save_number(save_number *input_number, save_number *who_next)
{
number=0;
next=who_next;
prv=NULL;
if (NULL!=who_next)
who_next->link(this);
plus_number(input_number);
}
~save_number()
{
if (prv!=NULL)
delete prv;
}
void link(save_number *new_prv)
{
prv=new_prv;
}
save_number *get_prv()
{
return prv;
}
save_number *get_next()
{
return next;
}
void ollim()
{
if (prv!=NULL)
{
prv->number_input(number/MAX_LONG);
number%=MAX_LONG;
}
else
{
prv=new save_number(number/MAX_LONG,this);
number%=MAX_LONG;
}
}
void plus_ollim()
{
if (prv!=NULL)
{
prv->plus_number_unsigned(number/MAX_LONG);
number%=MAX_LONG;
}
else
{
prv=new save_number(number/MAX_LONG,this);
number%=MAX_LONG;
}
}
int number_input(int input_number)
{
if (input_number>9 || input_number<0)
return FALSE;
number*=10;
number+=input_number;
if (number>=MAX_LONG)
ollim();
return TRUE;
}
unsigned __int64 call_number(int where_number)
{
if (0==where_number)
return number;
if (prv==NULL)
return MAX_LONG;
return prv->call_number(where_number-1);
}
void plus_number_unsigned(unsigned __int64 plus_input_number)
{
number+=plus_input_number;
if (number>=MAX_LONG)
plus_ollim();
}
int plus_number(int plus_input_number)
{
if (plus_input_number<0)
return FALSE;
plus_number_unsigned( plus_input_number);
return TRUE;
}
void plus_number(save_number *plus_target)
{
save_number *target=this;
register int i=0;
unsigned __int64 get_number;
while (1)
{
get_number=plus_target->call_number(i);
if (MAX_LONG==get_number)
break;
this->plus_number_unsigned(get_number);
if (target->get_prv()==NULL)
break;
target=target->get_prv();
++i;
}
while (1)
{
++i;
get_number=plus_target->call_number(i);
if (MAX_LONG==get_number)
break;
target=new save_number(get_number,target);
}
}
int compare_number(unsigned __int64 target_number)
{
if (number<target_number)
return 1;
if (number>target_number)
return -1;
return 0;
}
int compare_number(save_number *target_number)
{
register int i=0;
unsigned __int64 this_number=0;
unsigned __int64 taget_get_number=0;
while (this_number!=MAX_LONG)
{
if (taget_get_number==MAX_LONG)
return -1;
this_number=call_number(i);
taget_get_number=target_number->call_number(i);
++i;
}
if (taget_get_number!=MAX_LONG)
return 1;
while (1)
{
this_number=call_number(i);
taget_get_number=target_number->call_number(i);
if (this_number==taget_get_number && 0==i)
return 0;
this_number%=MAX_LONG; taget_get_number%=MAX_LONG;
if (this_number<taget_get_number)
return 1;
if (this_number>taget_get_number)
return -1;
--i;
}
}
int nanugi_2()
{
if (NULL!=prv)
{
if (1==prv->nanugi_2())
number+=MAX_LONG;
if (0==prv->call_number(0))
{
delete prv;
prv=NULL;
}
}
if (1==number%2)
{
number/=2;
return 1;
}
number/=2;
return 0;
}
};
void print_number(save_number *target)
{
save_number *temp_number=target;
while(NULL!=temp_number->get_prv())
temp_number=temp_number->get_prv();
while (NULL!=temp_number)
{
cout << temp_number->call_number(0);
temp_number=temp_number->get_next();
}
}
save_number *such_target_number(save_number *mokpyo, save_number *gaesu)
{
save_number *min_answer, *max_answer, *temp;
int result_compare;
min_answer=new save_number(1,NULL);
max_answer=new save_number(mokpyo,NULL);max_answer->plus_number(1);
temp=new save_number(min_answer,NULL);temp->plus_number(1);
result_compare=temp->compare_number(max_answer);
delete temp;
while (0!=result_compare)
{
save_number *temp_target, *temp_result;
temp_target=new save_number(min_answer,NULL);
temp_target->plus_number(max_answer);temp_target->nanugi_2();
temp_result=new save_number(1,NULL);
save_number *i=new save_number(0,NULL);
while(0!=i->compare_number(gaesu))
{
save_number *j=new save_number(1,NULL);
save_number *temp_plus=new save_number(temp_result,NULL);
while (0!=j->compare_number(temp_target))
{
temp_result->plus_number(temp_plus);
j->plus_number(1);
}
delete j;
delete temp_plus;
i->plus_number(1);
}
delete i;
int result_compare_second=temp_result->compare_number(mokpyo);
if (-1==result_compare_second)
{
delete max_answer;
max_answer=new save_number(temp_target,NULL);
}
else if (1==result_compare_second)
{
delete min_answer;
min_answer=new save_number(temp_target,NULL);
}
else
{
delete min_answer;delete max_answer;delete temp_result;
return temp_target;
}
temp=new save_number(min_answer,NULL);temp->plus_number(1);
result_compare=temp->compare_number(max_answer);
delete temp;
}
return NULL;
}
void main()
{
save_number *intput_number, *gob_gaesu;
intput_number=new save_number(0,NULL);
gob_gaesu=new save_number(0,NULL);
char temp=0;
cout << "제곱한 결과값을 입력해주세요. >>";
while (ENTER!=temp)
{
temp=getch();
if (47<temp && 58>temp)
{
intput_number->number_input(temp-48);
cout << temp;
}
}
temp=0; cout << "\n";
cout << "제곱한 회수를 입력해주세요. >>";
while (ENTER!=temp)
{
temp=getch();
if (47<temp && 58>temp)
{
gob_gaesu->number_input(temp-48);
cout << temp;
}
}
cout << "\n";
save_number *answer=such_target_number(intput_number,gob_gaesu);
if (NULL==answer)
cout << "잘못된 값을 입력하였습니다.\n";
else
{
cout << "결과값은 ";
print_number(answer);
cout << " 입니다.\n";
delete answer;
}
cout << "이용해주셔서 감사합니다.\n";
}