题目描述
给你一个 01 序列,HDLC 协议处理的话,如果出现连续的 5 个 1 会补 1 个 0。
例如 1111110,会变成 11111010。
现在给你一个经过 HDLC 处理后的 01 序列,你需要找到 HDLC 处理之前的 01 序列。
例如给你 11111010,你需要输出 1111110。
输入格式
第一行一个整数 N,表示共有 N 组测试数据。
每组数据占一行,包含一个 01 序列。
输出格式
每组数据输出一行结果,为处理之前的 01 序列。
数据范围
1≤N≤100,
01 序列长度不超过 100。
输入样例:
2
11111010
1111100
输出样例:
1111110
111110
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cstdio>
using namespace std;
const int N = 110;
string str;
int main(){
int T;
scanf("%d",&T);
while(T--){
int cnt = 0;
cin >> str;
string res = "";
int n = str.length();
for(int i = 0;i < n;++i){
if(str[i] == '1'){
res += "1";
cnt++;
}else{
res += "0";
cnt = 0;
}
if(cnt == 5){
cnt = 0;
i++;
}
}
cout << res << endl;
}
return 0;
}