编程题
空白格式化 ### 题目描述 **本题为代码补全填空题,请将题目中给出的源代码补全,并复制到右侧代码框中,选择对应的编译语言(C/Java)后进行提交。若题目中给出的源代码语言不唯一,则只需选择其一进行补全提交即可。复制后需将源代码中填空部分的下划线删掉,填上你的答案。提交后若未能通过,除考虑填空部分出错外,还需注意是否因在复制后有改动非填空部分产生错误。** 本次大赛采用了全自动机器测评系统。 如果你的答案与标准答案相差了一个空格,很可能无法得分,所以要加倍谨慎! 但也不必过于惊慌。因为在有些情况下,测评系统会把你的答案进行“空白格式化”。其具体做法是:去掉所有首尾空白;中间的多个空白替换为一个空格。所谓空白指的是:空格、制表符、回车符。 以下代码实现了这个功能。仔细阅读代码,填写缺失的部分。 ### 源代码 **C** ```c #include // 字符串的空白处理 void f(char* from, char* to) { char* p_from = from; char* p_to = to; while(*p_from==' ' || *p_from=='\t' || *p_from=='\n') p_from++; do{ if(*p_from==' ' || *p_from=='\t' || *p_from=='\n'){ do{p_from++;} while(*p_from==' ' || *p_from=='\t' || *p_from=='\n'); if(________________) *p_to++ = ' '; } }while(*p_to++ = *p_from++); } void test(char* s) { char buf[100]; buf[0] = 0; f(s,buf); printf("%c%s%c\n",'|',buf,'|'); } void myfunction() { test("\t abc \t \n\n \t\t "); test(" \t\t a b \t\t\t c\t \n"); test("\t \n "); } int main() { myfunction(); return 0; } ```
查看答案
赣ICP备20007335号-2