1.txt 內容依「|」分隔,分別輸出到「身份證.txt」、「金額.txt」、「代號.txt」三個檔案。1234567890|312|32145 1234567890|312|32145 ...(共 8 行)
1234567890 → 身份證.txt312 → 金額.txt32145 → 代號.txt(注意:範例輸出為 21145,推測為筆誤)#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], 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 位元組即完成,凸顯腳本語言在文字處理與代碼簡潔度上的優勢。這類「Code Golf」遊戲不僅考驗語言特性熟悉度,更能訓練演算法精簡與標準庫善用能力。C 語言雖冗長,但透過巨集、指標運算仍可進一步壓縮,值得持續探索。