vlatkovski

ABCDE * 4 = EDCBA

Jan 17th, 2017
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4.  
  5. using namespace std;
  6.  
  7. /*
  8.     ABCDE * 4 = EDCBA
  9. */
  10.  
  11. int main() {
  12.     ostringstream ss;
  13.  
  14.     int limit = 100000;
  15.  
  16.     for (int i = 10000; i < limit; i++) {
  17.         int i4 = i * 4;
  18.  
  19.         if (i4 >= limit) break;
  20.  
  21.         ss << i;
  22.         string is = ss.str(); //string i
  23.         ss.str("");
  24.  
  25.         string isr = ""; //string i, reversed
  26.         for (int x = is.length() - 1; x >= 0; x--) {
  27.             isr += is.at(x);
  28.         }
  29.  
  30.         ss << i4;
  31.         string i4s = ss.str(); //string i4
  32.         ss.str("");
  33.  
  34.         cout << "i:" << i << " 4*i:" << i4 << " ir:" << isr << endl;
  35.  
  36.         if (i4s == isr) {
  37.             cout << "Najdeno! " << i << endl;
  38.             break;
  39.         }
  40.     }
  41. }
  42.  
  43. /*
  44. int i
  45. string i
  46. int i4 = i * 4
  47. string i4
  48. proveri dali i4 == i.reverse()
  49. */
Advertisement
Add Comment
Please, Sign In to add comment