Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- verdict : Run Time Error
- */
- #include <iostream>
- #include <cstring>
- #include <string>
- #include <cmath>
- #include <cstdio>
- #include <cstdlib>
- #include <algorithm>
- #include <fstream>
- using namespace std;
- int binary_decimal(string a)
- {
- int d = 0;
- int j = 0;
- for (int i = a.length() - 1; i >= 0; i--)
- {
- int k = j;
- int m = (a[i] - '0');
- while (k--)
- {
- m *= 2;
- }
- d += m;
- j++;
- }
- return d;
- }
- string decimal_binary(int a)
- {
- string s = "";
- char t[1000000];
- int i = 0;
- int r = 0;
- while (1)
- {
- if (a == 0)break;
- r = a % 2;
- t[i] = char(r+48);
- i++;
- a = a / 2;
- }
- t[i] = '\0';
- s = t;
- reverse(s.begin(), s.end());
- return s;
- }
- string all_one(int d)
- {
- string s = "";
- while (d--)
- {
- s.append("1");
- }
- return s;
- }
- string decode(string header, string x)
- {
- int d = binary_decimal(x);
- int l = x.length() - 1;
- int k = 1;
- while (l--)
- {
- k *= 2;
- }
- d += k;
- if (x == "0")d = 0;
- if (x == "00")d = 1;
- if (x == "01")d = 2;
- if (x == "10")d = 3;
- char a[2];
- a[0] = header[d];
- a[1] = '\0';
- string s = a;
- return s;
- }
- int main()
- {
- string header;
- while (getline(cin, header))
- {
- string message = "";
- string a;
- char filter[1000000];
- filter[0] = '\0';
- while (1)
- {
- getline(cin, a);
- int j = 0;
- for (int i = 0; i < a.size(); i++)
- {
- if (a[i] != char(13))
- {
- filter[j] = a[i];
- j++;
- }
- }
- filter[j] = '\0';
- a = filter;
- message.append(a);
- if (a[a.length() - 1] == '0' && a[a.length() - 2] == '0' && a[a.length() - 3] == '0')
- {
- break;
- }
- }
- string result = "";
- a = message.substr(0, 3);
- int d = binary_decimal(a);
- int k = 3;
- string end = all_one(d);
- string t = message.substr(k, d);
- while (1)
- {
- while (1)
- {
- if (t == end)break;
- result.append(decode(header, t));
- k += d;
- t = message.substr(k, d);
- }
- k += d;
- a = message.substr(k, 3);
- if (a == "000")break;
- k += 3;
- d = binary_decimal(a);
- end = all_one(d);
- t = message.substr(k, d);
- }
- cout << result << endl;
- message = "";
- result = "";
- a = "";
- t = "";
- end = "";
- filter[0] = '\0';
- d = k = 0;
- header = "";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement