COULIX un pc pour les attirer ... | j ai fait ca depuis, sa narche , pour 196 je me suis entraun de calculer 100000 iterations.
Code :
- #include <iostream.h>
- #include <string>
- #include <fstream>
- #include <cstdlib>
- #include <time.h>
- //number 196 have not been find yet after more than 13 million digits.
- //i calculate 12000 digits, asking te program to stop after 30000 iterations,
- //it tooks 2 minutes on an AMD 1500 mhz.
- //the method i am using is not the more effecient, special librairies permit to
- //use realy large integer represented on as much bits as we wants, which is
- //more faster than checking digits by digits .
- //i check my result using this website.
- //http://www.jasondoucette.com/worldrecords.html
- //????????????????????????????????????????????????????????????????????????//
- // Palindrome checking function //
- //????????????????????????????????????????????????????????????????????????//
- bool palindrome (string a) {
- int len= a.length();
- for(int i=0; i<len;i++){
- if((a[i]*1)!=(a[len-i-1]*1)) { return false; }
- else continue;
- }
- return true;
- }
- //????????????????????????????????????????????????????????????????????????//
- // Inverse string function //
- //????????????????????????????????????????????????????????????????????????//
- string inversestr (string source,string target) {
- for(int i=0; i<(source.length());i++){
- target[i]=source[(source.length())-i-1]; }
- return target;
- }
- //????????????????????????????????????????????????????????????????????????//
- // Add digits string function //
- //????????????????????????????????????????????????????????????????????????//
- string process(string input) {
- string resultf,inverse;
- int tempa,tempinverse,tempresult;
- int temp=0;
- int len = input.length();
- inverse=input;
- string result(len,' ');
- resultf=result;
- inverse=inversestr(input,inverse);
- for(int i=0; i<len;i++) {
- tempa = (input[i]*1 -48);
- tempinverse = (inverse[i]*1 -48);
- if (tempa+tempinverse+temp >9) {
- tempresult= (tempa+tempinverse+temp)%10;
- temp = 1;
- result[i]=(tempresult+48);
- }
- else {
- tempresult = (tempa+tempinverse+temp);
- result[i]=(tempresult+48);
- temp=0;
- }
- }
- if (temp==1){
- result = result + '1';
- resultf = resultf + ' ';
- }
- resultf =inversestr(result,resultf);
- return resultf;
- }
- //????????????????????????????????????????????????????????????????????????//
- // Intro //
- //????????????????????????????????????????????????????????????????????????//
- void intro () {
- cout <<" \n";
- cout << " ///\\ \n";
- cout << " (@ @) \n";
- cout << " +---oOO----(_)---Ooo-----+ \n";
- cout << " | TAGMC21 © I \n";
- cout << " I Sibt feb 2003 | \n";
- cout << " I V 0.2 | \n";
- cout << " +------------------------+ \n";
- cout << " |__|__| \n";
- cout << " || || \n";
- cout << " ooO Ooo \n";
- cout <<" \n";
- cout <<"ASSIGNEMENT 4 : § Palindrome numbers § \n";
- cout <<"This program add any number entered to his reverse"<<endl;;
- cout << "until a palindrome number is the result.\n";
- cout << "A file : result.txt, contain the final palindrone number.\n";
- //cout << "resulting in a process less efficient\n";
- cout << "\n";
- }
- //????????????????????????????????????????????????????????????????????????//
- // Error input checking //
- //????????????????????????????????????????????????????????????????????????//
- bool checkinputcaract (string input) {
- for (int i=0; i<input.length(); i++) {
- if (input[i] != '0' && input[i] != '1' && input[i] != '2' && input[i] != '3'
- && input[i] != '4' && input[i] != '5' && input[i] != '6' && input[i] != '7'
- && input[i] != '8'&& input[i] != '9'&& input[i])
- return true;
- }
- return false;
- }
- //????????????????????????????????????????????????????????????????????????//
- // MAIN //
- //????????????????????????????????????????????????????????????????????????//
- int main()
- {
- string a,result,input,resultf,save;
- char quit;
- intro();
- do{
- cout << "----------------------------------------------\n";
- cout << "Enter number :";
- cin>>input ;
- save=input;
- while (checkinputcaract(input)==true) {
- cout << "! Error wrong input caracters !\n\a";
- cout << "Enter number :";
- cin>>input ;}
- int degree=0;
- cout << "\n";
- cout << "Wait processing . . .\n\n";
- do {
- input=process(input);
- degree++;
- if(degree > 100000) {break; }
- }
- while(palindrome(input)!=true);
- ofstream output;
- output.open ( "RESULT.txt" );
- output<< "number entered :" <<save<<"\n";
- output<< "Degree :" <<degree<<"\n";
- output<< "Numbr of digits :" <<input.length() <<"\n";
- output<< "Result :" <<input<<"\n\n\n";
- cout << "result : " <<input << "\n";
- cout << "degree : " << degree << "\n";
- cout << "number of digits : " <<input.length() << "\n\n";
- cout << "quit [y/n] ? ";
- cin >> quit;
- }
- while(quit!='y');
- }
|
Message édité par COULIX le 23-01-2003 à 04:01:02
|