题解 | #参数解析#
参数解析
https://www.nowcoder.com/practice/668603dc307e4ef4bb07bcd0615ea677
//从前往后遍历,可以采用二维数组简化代码 #include <stdio.h> #include<string.h> int main() { char arr[1000]; int i = 0, count = 0, flag = 0,a=0; gets(arr); int sz = strlen(arr); for (a = 0; a < sz; a++) { i = a; if (arr[i] == '"') { if (flag == 0) { flag = 1; } else { flag = 0; } } if (arr[i] == ' ') { if (!flag) { count++; } } } printf("%d\n",count+1); for (a = 0; a < sz; a++) { i = a; if(arr[i] != '"' && arr[i] != ' ') { printf("%c", arr[i]); } if (arr[i] == '"') { if (flag == 0) { flag = 1; } else { count++; flag = 0; } } if (arr[i] == ' ') { if (!flag) { count++; printf("\n"); } else { printf(" "); } } } return 0; }