题解 | #参数解析#
参数解析
https://www.nowcoder.com/practice/668603dc307e4ef4bb07bcd0615ea677
#include <stdio.h>
#include "string.h"
int main() {
char str[1000] = {0};
char yinghao = 0;
int cnt = 1;
char str2[1000] = {0};
int str2_index = 0;
gets(str);
for (int i = 0; str[i] != '\0'; i++) {
if (yinghao == 0) {
if (str[i] == ' ') {
cnt++;
sprintf(&str2[str2_index++], "\n");
} else if (str[i] == '\"') yinghao = 1;
else sprintf(&str2[str2_index++], "%c", str[i]);
} else {
if (str[i] == '\"') yinghao = 0;
else sprintf(&str2[str2_index++], "%c", str[i]);
}
}
printf("%d\n%s\n", cnt, str2);
return 0;
}
查看23道真题和解析