C,290字节
高尔夫功能B
,具有依赖关系;将输入作为以null终止的char *
#define l(s) strlen(s)
p(char*s,int n){while(n--)printf(s);}
B(char*s){char*t=strtok(s,"\n");int x=l(t),z=1;while(t=strtok(0,"\n"))z++,x=l(t)>x?l(t):x;p("╔",1);p("=",x+2);p("╗\n",1);while(z--)printf("║ %s", s),p(" ",x-l(s)),p(" ║\n",1),s+=l(s)+1;p("╚",1);p("=",x+2);p("╝\n",1);}
完全取消程序功能
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 1024
// GOLF-BEGIN =>
#define l(s) strlen(s)
// since multibyte chars don't fit in char: use char* instead
void p (char*s,int n){ while(n--)printf(s); }
void B (char *s){
char *t = strtok(s,"\n");
int x=l(t), z=1;
while(t=strtok(0,"\n"))z++,x=l(t)>x?l(t):x;
// x is l(longest line), z is #lines
p("╔",1);p("=",x+2);p("╗\n",1);
while(z--)printf("║ %s", s),p(" ",x-l(s)),p(" ║\n",1),s+=l(s)+1;
p("╚",1);p("=",x+2);p("╝\n",1);
}
// <= GOLF-END
int main(int argc, char **argv) {
char buffer[MAX];
memset(buffer, 0, MAX);
FILE *f = fopen(argv[1], "rb");
fread(buffer, 1, MAX, f);
B(buffer);
return 0;
}
输入
_.,----,._
.:' `:.
.' `.
.' `.
: :
` .'`':'`'`/ '
`. \ | / ,'
\ \ | / /
`\_..,,.._/'
{`'-,_`'-}
{`'-,_`'-}
{`'-,_`'-}
`YXXXXY'
~^^~
输出
╔======================╗
║ _.,----,._ ║
║ .:' `:. ║
║ .' `. ║
║ .' `. ║
║ : : ║
║ ` .'`':'`'`/ ' ║
║ `. \ | / ,' ║
║ \ \ | / / ║
║ `\_..,,.._/' ║
║ {`'-,_`'-} ║
║ {`'-,_`'-} ║
║ {`'-,_`'-} ║
║ `YXXXXY' ║
║ ~^^~ ║
╚======================╝
C打高尔夫球的技巧表示赞赏!