深信服校园招聘c/c 软件开发C卷
时长:120分钟 总分:100分
812浏览 5人已完成答题
题型介绍
题型 | 填空题 |
---|---|
数量 | 3 |
字符串匹配
函数match检查字符串str是否匹配模板pattern,匹配则返回0,否则返回-1。模板支持普通字符(a-z0-9A-Z)及通配符?
和*
。普通字符匹配该字符本身,?
匹配任意一个字符,*
匹配任意多个任意字符。比如字符串abc对下述模板的匹配结果为:
模板 | 结果 | 模板 | 结果 |
---|---|---|---|
abc | 0 | a*b | -1 |
a* | 0 | ab? | 0 |
a*c | 0 | a? | -1 |
请完成该函数代码:
int match(const char *str, const char *pattern)
{
}
字符串解析
以下函数解析字符串str是否合法的C语言字符串字面值定义(不考虑八进制和十六进制字符编码),如果是,则将解码后的内容保存到buf中,并返回0,否则返回-1。比如,"hello \"sangfor\""解码后结果为hello "sangfor",请完成该函数代码:
int unescape_c_quoted(char *buf, const char *str) { }
int main()
{
char str[10000]
char buf[10000]
int len
int ret
if (fgets(str, sizeof(str), stdin) == NULL) {
fprintf(stderr, "input error\n")
return 0
}
len = strlen(str)
while (len > 0 && isspace(str[len - 1])) {
str[len - 1] = '\0'
--len
}
ret = unescape_c_quoted(buf, str)
if (ret < 0)
printf("error\n")
else
printf("%s\n", buf)
fprintf(stderr, "input:%s\noutput:%s\n", str, buf)
return 0
}