一个编程游戏之文本处理(要求最短代码)
1.将1.txt的内容分离为3个文件(金额、身份证、代号).
2.为保证游戏公平,请将代码写为一行.(鉴于一些语言特性,直接计算代码文件大小)
3.代码数最少即为获胜(计算空格).1.txt
1234567890|312|32145
1234567890|312|32145
1234567890|312|32145
1234567890|312|32145
1234567890|312|32145
1234567890|312|32145
1234567890|312|32145
1234567890|312|321451234567890 输出到 身份证.txt
312 输出到 金额.txt
21145 输出到 代号.txt下面是我用c写的view plaincopy to clipboardprint?
#include <stdio.h>
#include <windows.h>
FILE* G;
char* wN[6] = {"身份证:","金额:","代号:","身份证.txt","金额.txt","代号.txt"};
main(int argc,char* argv[]){
if(argc == 2){
char T[256];
char w[64];
FILE* f;
char* p;
int i;
f = fopen(argv[1],"r");
while(fgets(T,80,f)){
i = 0;
p = strtok(T,"|");
while(p != 0){
sprintf(w,"%s%s%s",wN[i],p,i<2?" ":""); //需要处理换行
G = fopen(wN[i+3],"a+");
fwrite(w,strlen(w),1,G);
fclose(G);
p = strtok(0,"|");
i++;
}
}
}
}
#include <stdio.h>
#include <windows.h>FILE* G;
char* wN[6] = {"身份证:","金额:","代号:","身份证.txt","金额.txt","代号.txt"};main(int argc,char* argv[]){
if(argc == 2){
char T[256];
char w[64];
FILE* f;
char* p;
int i;
f = fopen(argv[1],"r");
while(fgets(T,80,f)){
i = 0;
p = strtok(T,"|");
while(p != 0){
sprintf(w,"%s%s%s",wN[i],p,i<2?" ":""); //需要处理换行
G = fopen(wN[i+3],"a+");
fwrite(w,strlen(w),1,G);
fclose(G);
p = strtok(0,"|");
i++;
}
}
}
}
--------------------------
感觉还是脚本写的代码简短,同事用python写代码的只有256字节,我这居然有500+字节
补充:软件开发 , C语言 ,