Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Paladrone

Name: Anonymous 2006-12-21 8:33

Optimize this code bitches!

#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{

     long a,b,c,d,e,f;
     char exit;

     cout << "Please input a 5 digit paladrone number: ";
     cin >> a;

     b = a/10000;
     cout << b << endl;
     c = (a%10000/1000);
     cout << c << endl;
     d = (a%1000/100);
     cout << d << endl;
     e = (a%100/10);
     cout << e << endl;
     f = a%10;
     cout << f << endl;

     if (b == 0) {cout << "That isn't a 5 digit number";}
     else if (b != c){cout << "The first number doesn't match with the last";}
     else if (f != d) {cout << "The secound number doesn't match with the fourth";}
     else {cout << b << f << e << d << c << " is a paladrone";}     return 0;


}

Name: Anonymous 2006-12-25 18:26 (sage)

>>23
simply because something is made out of numerals, doesn't mean that you have to manage it as ints or longs or even bignums for that matter.
Obviously. However, given x bytes, the string representation will be able to hold values up to 10^x, whereas a pure binary representation can hold values up to 256^x; an immense difference in efficiency. In this case, for the sake of simplicity, (dynamically allocated) strings work best, but usually you should go with bignums when you need to work with arbitrarily large numbers.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List