Text processing for a programming game (requires the shortest code)

Source: Internet
Author: User
Tags strtok

1.separate 1.txt content into three files (amount, ID card, code ).
2. to ensure fairness in the game, write the code as a line (for some language features, directly calculate the size of the code file)
3. The minimum number of codes indicates the winner (space calculation ).

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 output to ID card .txt
312 output to amount .txt
21145 output to generation number .txt

Below is the view plaincopy to clipboardprint I wrote in c?
# Include <stdio. h>
# Include <windows. h>

FILE * G;
Char * wN [6] = {"ID card:", "amount:", "Code:", "ID card .txt", "amount .txt", "Number .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", wN [I], p, I <2? "": ""); // Line feed needs to be processed
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] = {"ID card:", "amount:", "Code:", "ID card .txt", "amount .txt", "Number .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", wN [I], p, I <2? "": ""); // Line feed needs to be processed
G = fopen (wN [I + 3], "a + ");
Fwrite (w, strlen (w), 1, G );
Fclose (G );
P = strtok (0, "| ");
I ++;
}
}
}
}
--------------------------
I think the script code is short. My colleagues only write 256 bytes of code using python. I actually have 500 + bytes.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.