cses

cses solutions in pure c
git clone git://git.superpozycja.net/cses
log | files | refs

s.c (438B)


      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 #include <string.h>
      4 #include <stdint.h>
      5 
      6 int putb(unsigned long long n, unsigned long long sz)
      7 {
      8 	char b[sz + 1];
      9 	char *p = b + sizeof(b);
     10 	*--p = 0x00;
     11 	do {
     12 		*--p = 0x30 + (n & 1);
     13 		n >>= 1;
     14 	} while (sz--);
     15 	return puts(b);
     16 }
     17 
     18 int solve()
     19 {
     20 	int n;
     21 
     22 	scanf("%d", &n);
     23 	for (int i = 0; i < 1 << n; i++)
     24 		putb((i ^ i >> 1), n);
     25 
     26 	return 0;
     27 }
     28 
     29 int main()
     30 {
     31 	int t = 1;
     32 	while (t--)
     33 		solve();
     34 }