bupt 2016-2

2.寻找变化前01序列


问题描述

给你一个01序列,HDLC协议处理的话,如果出现连续的5个1会补1个0。例如1111110,会变成11111010。

现在给你一个经过HDLC处理后的01序列,你需要找到HDLC处理之前的01序列。

例如给你11111010

你需要输出1111110



Input

输入正整数N,表示N例测试。接着输入N组数据,每组输入经过HDLC处理过的01序列(长度小于100)。

Output

对每组输入数据,输出HDLC处理前的01序列。


Sample Input

2

11111010

1111100

Sample Output

1111110

111110



c++版 :借鉴葡萄家


#include <iostream>
#include<cstring>
#define N 105
using namespace std;


int main(){
int i,tes,count;
char a[N];//此处得用字符型,若用整型编译通过不了
while(cin>>tes){
while(tes--){
cin>>a;
count=0;
for(i=0;i<strlen(a);i++){
if(49==a[i]){//a现在是字符型,判断是否相等得加‘1’,或者等于49(ASCII)
cout<<a[i];
count++;
if(5==count){
  i++;
  count=0;
}
}else{
                  count=0;  
  cout<<a[i];//别忘了此处打印0
}
}
cout<<endl;//cout 注意编写正确
}

}
system("pause");
return 0;
}

C语言版:

#include<stdio.h>
#include<string.h>
#define N 100


int main(){
int i,num,count;
char a[N];
while(scanf("%d",&num)!=EOF){
while(num--){
scanf("%c",a);//c或者s都可以
count=0;
for(i=0;i<strlen(a);i++){
if(49==a[i]){
count++;
printf("%c",a[i]);
if(5==count){
i++;
count=0;
}
}else{
count=0;
printf("%c",a[i]);
}
}
}
printf("\n");
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值