输入格式:
首个字符是字符,并且每个单词之间只有一个空格
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
char str[1000];
fgets(str, 1000, stdin);
int n = strlen(str);
for (int i = 0; i < n; i++)
{
int j = i;
while (j < n && str[j] != ' ') j++;
for (int k = i; k < j; k++)
cout << str[k];
cout << endl;
i = j;
}
}
输入:
abc ahfkhf klo lp
输出:
abc
ahfkhf
klo
lp