SHARE
TWEET

Untitled

a guest May 24th, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<vector>
  4.  
  5. using namespace std;
  6.  
  7. vector<int> banda;
  8.  
  9. void afisareBanda() {
  10.     cout << "Banda:" << endl;
  11.     vector<int>::iterator it;
  12.     for (it = banda.begin(); it != banda.end(); it++) {
  13.         cout << *it << endl;
  14.     }
  15. }
  16. int main()
  17. {
  18.     cout << "Test";
  19.    
  20.     int numar;
  21.     cout << "Introdu numarul in binar:" << endl;
  22.     cin >> numar;
  23.     int stareaInitiala = 0;
  24.     int stareaCurenta = stareaInitiala;
  25.     bool stareaFinala = false;
  26.     int s = 0;
  27.     int c = 0;
  28.     while (numar>0)
  29.     {
  30.         c = numar % 10;
  31.         s++;
  32.         banda.push_back(c);
  33.         numar = numar / 10;
  34.     }
  35.     cout << "Numarul cifrelor: " << s << endl;
  36.     afisareBanda();
  37.  
  38.     int ok = 1;
  39.     int start = 0;
  40.     int end = s - 1;
  41.     vector<int>::iterator it;
  42.     while (stareaFinala != true) {
  43.         if (banda.at(start) == banda.at(end) && !banda.empty()) {
  44.             banda.erase(banda.begin());
  45.             banda.erase(banda.end()-1);
  46.             start++;
  47.             end--;
  48.  
  49.         }
  50.         else {
  51.             stareaFinala = true;
  52.             ok = 0;
  53.         }
  54.     }
  55.  
  56.     if (ok == 1) {
  57.         cout << "Numarul este palindrom!" << endl;
  58.     }
  59.     else {
  60.         cout << "Numarul nu ete palidrom!" << endl;
  61.     }
  62.     //while (stareaFinala != true) {
  63.  
  64.     //}
  65.     return 0;
  66. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top