Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2014
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.64 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <memory.h>
  4. #include <string.h>
  5. char t[2][2][2] = {'0','1','2','3','4','5','6','7'};
  6. #define z(s,n) (s[n]=='0')?0:1
  7. #define B(s) t[z(s,0)][z(s,1)][z(s,2)]
  8. int main(void)
  9. {
  10. FILE *f;long l,a;char *b,*n;int i,j=0;
  11. f=fopen("i","r");
  12. fseek(f,0,SEEK_END);
  13. l=ftell(f);
  14. fseek(f,0,SEEK_SET);
  15. b=calloc(1,l+1);
  16. a=((l-1)/3)+((((l-1)%3)>0)?1:0);
  17. n=calloc(1,a+1);
  18. fgets(b,l,f);
  19. fclose(f);
  20.  
  21. n[a] = 0;
  22. for(i=l-4;i>-1;i-=3)
  23. {
  24. n[(a-1)-(j++)]=B((&b[i]));
  25. if(i>0)b[i] = 0;
  26. }
  27.  
  28. if(i==-2)n[0]=t[0][0][z(b,0)];
  29. if(i==-1)n[0]=t[0][z(b,1)][z(b,0)];
  30.  
  31. f=fopen("o","w");
  32. fputs(n,f);
  33. fclose(f);
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement