#include<stdio.h>
#include<stdlib.h>
int* manchester(int *arr,int len)
{
int* res=(int*)malloc(sizeof(int)*len);
arr[-1]=0;
for(int i=0;i<len;i++)
{
res[i]=arr[i]==arr[i-1]?0:1;
}
return res;
}
int main() {
int n,a[100],i;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
int* x=manchester(a,n);
for(i=0;i<n;i++)
printf("%d ",x[i]);
}
#include<stdlib.h>
int* manchester(int *arr,int len)
{
int* res=(int*)malloc(sizeof(int)*len);
arr[-1]=0;
for(int i=0;i<len;i++)
{
res[i]=arr[i]==arr[i-1]?0:1;
}
return res;
}
int main() {
int n,a[100],i;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
int* x=manchester(a,n);
for(i=0;i<n;i++)
printf("%d ",x[i]);
}
input:
8
0 1 0 0 1 1 1 0
output:
0 1 1 0 1 0 0 1
No comments:
Post a Comment