14917 - Red Cape Flying Cat's git project 2   

Description

Story

(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!

 

Problem Statement

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:

 

1. Validate Commit Message

Goal

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.

 

Constraint

  • The length of message is 0~50 characters, composed of uppercase/lowercase English letters, digits, spaces, and colons.

 

Example

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

 

2. Match Filename

 

Goal

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 headbodytail is an empty string "", skip the corresponding check.

 

Constraint

  • filename is composed of [1~10 uppercase/lowercase English letters].[1~10 uppercase/lowercase English letters].
  • headbodytail are each either an empty string "" or a string composed of uppercase/lowercase English letters and ..
  • len of headbodytail is between 1 and 20 (inclusive) if not empty.
  • Each character appears at most once in total across headbody, and tail.

 

Example

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:


 

3. Filter Filenames

 

Goal

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 headbodytail is an empty string "", skip the corresponding check.

 

Constraint

  • filenames is a string with the format <file1> <file2> ... <fileN>, where files are separated by exactly one space. At least one file is present.
  • Each file is composed of [1~10 uppercase/lowercase English letters].[1~10 uppercase/lowercase English letters].
  • headbodytail are each either an empty string "" or a string composed of uppercase/lowercase English letters and ..
  • len of headbodytail is between 1 and 20 (inclusive) if not empty.
  • Each character appears at most once in total across headbody, and tail.

 

Example

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]

 

Subtask

We strongly recommend that you complete the following subtasks in order (note: subtask 6 may be relatively easy for some people).

Input

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.

Output

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>]

Sample Input  Download

Sample Output  Download

Partial Judge Code

14917.c

Partial Judge Header

14917.h

Tags




Discuss