Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <conio.h>
- #include <string>
- #include <cmath>
- using namespace std;
- int main()
- {
- int i, j;
- string obr;
- getline(cin, obr);
- int size = obr.size();
- if (size > 8) {
- cout << "Its should be 8 bits ";
- _getch();
- return 0;
- }
- for (i = 0; i < size; i++) {
- if (obr[i] != '1') {
- if (obr[i] != '0') {
- cout << "Its should be only 0s and 1s ";
- _getch();
- return 0;
- }
- }
- }
- char *temp = new char[size];
- for (i = 0; i < size; i++) {
- temp[i] = '\0';
- }
- if (obr[0] == '1') {
- temp[0] = '-';
- for (i = size - 1; i > 0; i--) {
- if (obr[i] == '1') {
- temp[i] = '0';
- }
- else temp[i] = '1';
- }
- }
- else {
- for (i = size - 1; i > 0; i--) {
- temp[i] = obr[i];
- temp[0] = '+';
- }
- }
- /*for (i = 0; i < size; i++) {
- cout << temp[i];
- }*/
- int count = 0;
- for (i = 1; i < size - 1; i++) {
- if (temp[i] == '0' && temp[i + 1] == '0') {
- count = 1;
- }
- else break;
- }
- for (i = 1; i < size - 1; i++) {
- if (temp[i] == '0' && temp[i + 1] == '0') {
- count++;
- }
- else break;
- }
- char *nat = new char[size - count];
- nat[0] = temp[0];
- for (i = 1 + count, j = 1; i < size - 1, j < size - count;i++,j++) {
- nat[j] = temp[i];
- }
- cout << '\n';
- for (i = 0; i < size - count; i++) {
- cout << nat[i];
- }
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement