(The following story is irrelevant to the problem description.)
As you know, you helped Red Cape Flying Cat develop a Git tool that became a massive success within the Computer Science department. Now, every CS student at NTHU is using the tool you two created, and Red Cape Flying Cat has become the most beloved and adorable cat in the entire department.
However, while working on his assignments on a tablet, he realized there isn't a Git tool specifically optimized for tablets, which has caused him quite a bit of frustration. Because of this, he wants to team up with you again to develop a tablet-specific Git tool so he can finally handle version control on his tablet with ease!

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 three functions:
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:
void print(int result) {
if (result == 1) printf("Commit message is valid\n");
else printf("Commit message is invalid\n");
}
print(is_valid_commit_message(""));
print(is_valid_commit_message("feat: add search bar"));
print(is_valid_commit_message("chore: I dont know what to write"));
output:
Commit message is invalid
Commit message is valid
Commit message is invalid
Your goal is to implement a function that checks whether a filename matches a given pattern:
int check_filename(const char *head, const char *body, const char *tail, const char *filename);
Return 1 if all of the following conditions hold for the non-empty arguments, otherwise return 0:
head is a prefix of filename.tail is a suffix of filename.body exists as a substring of filename, strictly after head and strictly before tail.If any of head, body, tail is an empty string "", skip the corresponding check.
filename is composed of [1~10 uppercase/lowercase English letters].[1~10 uppercase/lowercase English letters].head, body, tail are each either an empty string "" or a string composed of uppercase/lowercase English letters and ..head, body, tail is between 1 and 20 (inclusive) if not empty.head, body, and tail.
code:
void print(int result) {
if (result == 1) printf("Filename matches\n");
else printf("Filename does not match\n");
}
print(check_filename("dev", "", "", "devmain.c"));
print(check_filename("dev", "main", "", "devmain.c"));
print(check_filename("dev", "main", ".c", "devmain.c"));
print(check_filename("main", "dev", "", "devmain.c"));
print(check_filename("dev", "xyz", "", "devmain.c"));
print(check_filename("dev", "main", ".py", "devmain.c"));
print(check_filename("main", "", "", "devmain.c"));
print(check_filename("dev", "", "main", "devmain.c"));
output:
Filename matches
Filename matches
Filename matches
Filename does not match
Filename does not match
Filename does not match
Filename does not match
Filename does not match
Explanation:

Your goal is to implement a function that filters a list of filenames:
int filter_filenames(const char *head, const char *body, const char *tail, char *filenames, char *result[]);
Parse filenames and place each filename that satisfies check_filename(head, body, tail, filename) into result[0], result[1], ... in order. Return the total number of matched files.
Each result[i] should point directly into filenames.
If any of head, body, tail is an empty string "", skip the corresponding check.
filenames is a string with the format <file1> <file2> ... <fileN>, where files are separated by exactly one space. At least one file is present.[1~10 uppercase/lowercase English letters].[1~10 uppercase/lowercase English letters].head, body, tail are each either an empty string "" or a string composed of uppercase/lowercase English letters and ..head, body, tail is between 1 and 20 (inclusive) if not empty.head, body, and tail.
code:
char filenames[] = "devmain.c main.c main.cpp";
char *result[55] = {NULL};
int k = filter_filenames("main", "", "", filenames, result);
printf("There have %d filenames: [%s, %s]\n", k, result[0], result[1]);
output:
There have 2 filenames: [main.c, main.cpp]
We strongly recommend that you complete the following subtasks in order (note: subtask 6 may be relatively easy for some people).

The first line contains a single integer Q (1 <= Q <= 100000), representing the total number of function calls.
Each line must not exceed 50 characters in length.
The three functions are called in the following format:
1 "<message>"
2 <head> <body> <tail> <filename>
3 <head> <body> <tail> <file1> <file2> ... <fileN>
For operations 2 and 3, use - to represent a "" argument.
The output should have Q lines, corresponding to the return value of each function call.
Commit message is valid
Filename matches
There have <k> filenames: [<file1>, <file2>, ..., <filek>]