C,189字节
#include<stdio.h>
s,t[9];
#define o(f,p)int*f=fopen(p,"ab+");
#define f(p,q,r)o(a,p)o(b,q)o(c,r)fscanf(a,"%*s %*d %*d %n",&s);for(fwrite(t,1,fread(t,1,s,b),c);s=~getc(a);putc(~s^getc(b),c))
在PBM图像上运行。f(a, b, out)
使用输入文件和输出文件的名称进行调用。
假设:
取消说明:(省略反斜杠)
// Scratch variable and "big enough" buffer
s, t[9];
// Opens a file in read/append binary mode
#define o(f,p)int*f=fopen(p,"ab+");
#define f(p, q, r)
// Open the three file pointers a, b, c from the paths p, q, r
o(a, p)
o(b, q)
o(c, r)
// Read from a to locate the end of the PBM header
fscanf(a, "%*s %*d %*d %n", &s);
for(
// Read the header from b into the buffer,
// then write it back from the buffer to c
fwrite(t, 1, fread(t, 1, s, b), c);
// Loop condition: get the next byte from a
// and check for EOF with a bitwise-not
// (Assumes that EOF == -1)
s = ~getc(a);
// Loop increment: get the next byte from b,
// flip s back, xor and write to c
putc(~s ^ getc(b), c)
) // Snatch the semicolon from the call syntax :)
C(规范弯曲),149字节
#include<stdio.h>
t[7];
#define o(f,p,u)int*f=fopen(p,"ab+");u(t,1,7,f);
#define f(p,q,r)o(a,p,fread)o(b,q,fread)o(c,r,fwrite)putc(getc(a)^getc(b),c)
仍使用PBM文件,但现在:
在填充文件t
头的同时向前搜索这两个文件,然后读取,异或将最后一个字节写回。利用fread
并fwrite
具有相似的参数列表来将同一宏后面的标头上的所有三个操作都分解为因子。