Untitled
unknown
plain_text
2 years ago
2.3 kB
4
Indexable
#include<bits/stdc++.h> using namespace std; void input( int& no_of_input, vector<string>& data ){ cout << "Enter the number of data you want to enter: "; cin >> no_of_input; cout << "Enter data: "; for( int i = 0; i < no_of_input; ++i ){ string s; cin >> s; data.push_back( s ); } } vector<string> stuff_data(int& no_of_data, vector<string>& data){ vector<string> res; for( int i = 0; i < no_of_data; ++i ){ string s = data[i]; string str = ""; int conseq_one_cnt = 0; str += "01111110"; for( int j = 0; j < (int)s.size(); ++j ){ char ch = s[j]; str.push_back(ch); if( ch == '1' ) ++conseq_one_cnt; else conseq_one_cnt = 0; if( conseq_one_cnt == 5 ) str.push_back('0'), conseq_one_cnt = 0; } str += "01111110"; res.push_back(str); } return res; } vector<string> destuff_data(int& no_of_input, vector<string>& data ){ vector<string> res; for( int i = 0; i < no_of_input; ++i ){ string& d = data[i]; int conseq_one_cnt = 0; string str=""; for( int j = 8; j < (int)d.size()-8; ++j ){ char ch = d[j]; if( conseq_one_cnt == 5 ){ conseq_one_cnt = 0; continue; } if( ch == '1' ) ++conseq_one_cnt; else conseq_one_cnt = 0; str.push_back(ch); } res.push_back(str); } return res; } void Output(int& no_of_input,vector<string>& data ){ cout << "Output " << endl; for( int i = 0; i < no_of_input; ++i ){ string& d = data[i]; cout << "\t" << d << endl; } } int main(){ int no_of_input; vector<string> data; input(no_of_input,data); vector<string> stuffed_data = stuff_data(no_of_input,data); cout << endl << endl << "Stuffed data output: " << endl; Output(no_of_input,stuffed_data); vector<string> destuffed_data = destuff_data(no_of_input,stuffed_data); cout << endl << endl << "De-stuffed data output: " << endl; Output(no_of_input,destuffed_data); return 0; }
Editor is loading...