更新时间:2022-09-18 17:59:24
恭喜你进入了蓝桥杯总决赛,本次大赛採用了全自己主动机器測评系统。
假设你的答案与标准答案相差了一个空格,非常可能无法得分,所以要加倍慎重。
但也不必过于惊慌。
由于在有些情况下,測评系统会把你的答案进行“空白格式化”。其详细做法是:去掉全部首尾空白;中间的多个空白替换为一个空格。
所谓空白指的是:空格、制表符、回车符。
下面代码实现了这个功能。细致阅读代码,填写缺失的部分,并补充完整使其可以工作。
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++);
}
一行代码。不是标准格式。
输出代码的标准形式。
char* p_from = from;
char* p_from = from;
代码的标准格式是。首尾没有空格。中间有空格的地方应该仅仅有一个空格不能有多个。
代码
#include <iostream> #include <cstdio> using namespace std; 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_from!=' '&&*p_from!='\t' && *p_from!='\n') *p_to++ = ' '; } } while(*p_to++ = *p_from++); } int main() { char a[1000],b[1000]; while(gets(a)) { f(a,b); cout<<b<<endl; } return 0; }