(The following story is irrelevant to the problem description.)
To save computer science students from the torture of teammates who don't know how to use git, Red Cape Flying Cat uses his knowledge from Introduction to Programming (II) to develop a git tool for everyone to use.
You, while developing alongside him, suddenly remember that you recently learned some string functions. Therefore, you decide to be responsible for some of the string processing parts.

This is a partial judge problem.
In a single test case, the total number of function calls will not exceed 100000.
You need to implement the following five functions:
Your goal is to implement a function that determines the type of a command:
int get_command_type(const char *command);
If the command:
git add, then return 0git commit, then return 1git log, then return 2command is guaranteed not to exceed 50 characters.command is a git command, and its format must be one of the following three:
git add <file1> <file2> ...git commit -m "<message>"git log[1~10 uppercase/lowercase English letters].[1~10 uppercase/lowercase English letters].code:
int t1 = get_command_type("git add a.txt b.txt");
if (t1 == 0) printf("Command type: add\n");
int t2 = get_command_type("git commit -m \"feat: add search bar\"");
if (t2 == 1) printf("Command type: commit\n");
int t3 = get_command_type("git log");
if (t3 == 2) printf("Command type: log\n");
output:
Command type: add
Command type: commit
Command type: log
You can use the following functions to implement the solution:
Your goal is to implement a function that checks whether a commit message is valid:
int is_valid_commit_message(const char *message);
If the length of message is between 1 and 20 (inclusive), it is considered valid, and you should return 1; if it is an empty string or its length exceeds 20 characters, return 0.
message is 0~50 characters, composed of uppercase/lowercase English letters, digits, spaces, and colons.code:
if (is_valid_commit_message("") == 1) {
printf("Commit message is valid\n");
} else {
printf("Commit message is invalid\n");
}
if (is_valid_commit_message("feat: add search bar") == 1) {
printf("Commit message is valid\n");
} else {
printf("Commit message is invalid\n");
}
if (is_valid_commit_message("chore: I dont know what to write") == 1) {
printf("Commit message is valid\n");
} else {
printf("Commit message is invalid\n");
}
output:
Commit message is invalid
Commit message is valid
Commit message is invalid
You can use the following functions to implement the solution:
Your goal is to implement a function that parses the list of files following a git add command:
int parse_filenames(char *filenames, char *result[]);
You need to sequentially place each file from left to right into positions 0, 1, 2... of the result array, and return the total number of files parsed.
filenames is a string with the format <file1> <file2> ... <fileN>, where each file is separated by exactly one space.[1~10 uppercase/lowercase English letters].[1~10 uppercase/lowercase English letters].code:
char filenames[] = "a.txt b.txt c.txt";
char *result[55] = {NULL};
int k = parse_filenames(filenames, result);
printf("There have %d filenames: [%s, %s, %s]\n", k, result[0], result[1], result[2]);
output:
There have 3 filenames: [a.txt, b.txt, c.txt]
You can use the following functions to implement the solution:
Your goal is to implement a function that generates a short Hash ID:
void get_short_commit_id(const char *hex, char *result);
You need to copy the "first 7 characters" of hex into the result array, and append the C string termination character \0 at the end.
hex is a string with a length between 7 and 50, composed entirely of digits 0~9 and lowercase letters a~f.code:
char result[55] = {0};
get_short_commit_id("923fba7d39452eb573aa3834", result);
printf("Short commit ID: %s\n", result);
output:
Short commit ID: 923fba7
You can use the following functions to implement the solution:
Your goal is to implement a function that automatically applies the Commit message convention:
void generate_commit_message(const char *type, const char *message, char *result);
You need to combine them into <type>: <message> and place it into result, according to the following rules:
type is exactly equal to feat, fix, or docs, directly use that type as the classification prefix.type is any string other than these three, forcibly change the classification to chore.type is 1~10, composed of uppercase/lowercase English letters.message is 1~20, composed of uppercase/lowercase English letters and spaces.code:
char res1[100] = {0}, res2[100] = {0};
generate_commit_message("feat", "add search bar", res1);
generate_commit_message("random", "fix typo", res2);
printf("Generated commit message: %s\n", res1);
printf("Generated commit message: %s\n", res2);
output:
Generated commit message: feat: add search bar
Generated commit message: chore: fix typo
You can use the following functions to implement the solution:
The first line contains a single integer Q (1 <= Q <= 100000), representing the total number of operations.
Each line of input is guaranteed to be no longer than 50 characters.
The above five operations are input in the following format:
1 <command>
2 "<message>"
3 <file1> <file2> ... <fileN>
4 <hex>
5 <type> "<message>"
The output should have Q lines, corresponding to the output of each operation.
Command type: <result>
Commit message is valid
There have <k> filenames: [<file1>, <file2>, ...]
Short commit ID: <result>
Generated commit message: <result>