Sunday, January 20, 2019

Manchestor program

#include<stdio.h>
#include<stdlib.h>
int* mac(int *a,int l)
{
    int* res=(int*)malloc(sizeof(int)*l);
    a[-1]=0;
    for(int i=0;i<l;i++)
    {
        res[i]=a[i]==a[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=mac(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