SHARE
TWEET

Untitled

a guest Dec 8th, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <conio.h>
  4. #include <string>
  5. #include <cmath>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.     int i, j;
  12.     string obr;
  13.     getline(cin, obr);
  14.     int size = obr.size();
  15.     if (size > 8) {
  16.         cout << "Its should be 8 bits ";
  17.         _getch();
  18.         return 0;
  19.     }
  20.     for (i = 0; i < size; i++) {
  21.         if (obr[i] != '1') {
  22.             if (obr[i] != '0') {
  23.                 cout << "Its should be only 0s and 1s ";
  24.                 _getch();
  25.                 return 0;
  26.             }
  27.         }
  28.     }
  29.     char *temp = new char[size];
  30.     for (i = 0; i < size; i++) {
  31.         temp[i] = '\0';
  32.     }
  33.     if (obr[0] == '1') {
  34.         temp[0] = '-';
  35.         for (i = size - 1; i > 0; i--) {
  36.             if (obr[i] == '1') {
  37.                 temp[i] = '0';
  38.             }
  39.             else temp[i] = '1';
  40.         }
  41.     }
  42.     else {
  43.         for (i = size - 1; i > 0; i--) {
  44.             temp[i] = obr[i];
  45.             temp[0] = '+';
  46.         }
  47.     }
  48.  
  49.     /*for (i = 0; i < size; i++) {
  50.         cout << temp[i];
  51.     }*/
  52.  
  53.     int count = 0;
  54.     for (i = 1; i < size - 1; i++) {
  55.         if (temp[i] == '0' && temp[i + 1] == '0') {
  56.             count = 1;
  57.         }
  58.         else break;
  59.     }
  60.     for (i = 1; i < size - 1; i++) {
  61.         if (temp[i] == '0' && temp[i + 1] == '0') {
  62.             count++;
  63.         }
  64.         else break;
  65.     }
  66.  
  67.     char *nat = new char[size - count];
  68.     nat[0] = temp[0];
  69.     for (i = 1 + count, j = 1; i < size - 1, j < size - count;i++,j++) {
  70.             nat[j] = temp[i];
  71.     }
  72.  
  73.     cout << '\n';
  74.  
  75.     for (i = 0; i < size - count; i++) {
  76.         cout << nat[i];
  77.     }
  78.  
  79.     _getch();
  80.     return 0;
  81. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top