The machine questions for Huawei 2014 campus recruitment are exactly the same as those for 2013.
I. Question description (60 points ):
Enter a string of lowercase letters (~ Z. Compile a character string filter program. If multiple identical characters appear in the string, filter out non-first-time characters.
For example, the "abacacde" character string is "abcde ".
Required implementation function: void stringFilter (const char * pInputStr, long lInputLen, char * pOutputStr );
[Input] pInputStr: input string
LInputLen: length of the input string
[Output] pOutputStr: Output string. The space has been opened up and the length of the input string is equal to that of the input string;
[Note] You only need to complete the function algorithm, and there is no IO input or output in the middle.
Example
Input: "deefd" output: "def"
Input: "afafaf" output: "af"
Input: "pppppppp" output: "p"
The main function has been hidden. This is the test entry reserved for users. Here, you can test your implementation function and call printf to print the output.
Currently, you can use other methods to test the function. You only need to ensure that the final program can be correctly executed. The function implementation can be modified without changing the function prototype. Make sure that compilation and running are not affected.
Ii. Question description (40 points ):
Enter a string of lowercase letters (~ Z. Compile a character string compression program to compress duplicate letters that are present continuously in the string and output the compressed character string.
Compression rules:
1. Only compress the repeated characters. For example, the compressed string "abcbc" is still "abcbc" because there are no consecutive duplicate characters ".
2. The format of the compressed field is "repeated characters + characters ". For example, after the string "xxxyyyyz" is compressed, it becomes "3x6yz ".
Required implementation functions:
Void stringZip (const char * pInputStr, long lInputLen, char * pOutputStr );
[Input] pInputStr: input string
LInputLen: length of the input string
[Output] pOutputStr: Output string. The space has been opened up and the length of the input string is equal to that of the input string;
[Note] You only need to complete the function algorithm, and there is no IO input or output in the middle.
Example
Input: "cccddecc" output: "3c2de2c"
Input: "adef" output: "adef"
Input: "pppppppp" output: "8 P"
Next, let's take a look at the highlights of page 2nd: