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|32145
1234567890 輸出到 身份證.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+字節