翻轉字串裡的單詞 C語言

2021-09-06 23:57:31 字數 631 閱讀 4699

問題:

給定乙個字串,逐個翻轉字串中的每個單詞。

示例:輸入:「the sky is blue」,

輸出:「blue is sky the」.

說明:無空格字元構成乙個單詞。

輸入字串可以在前面或者後面包含多餘的空格,但是反轉後的字元不能包括。

如果兩個單詞間有多餘的空格,將反轉後單詞間的空格減少到只含乙個。

#include #include #include #define in 1

#define out 0

void reverse(char *start, char *end)

}void reverse_word(char *s) else if (isalnum(*s) && flag == out)

s += 1;

}if (flag == in)

}void filling_space(char *s) else if (isalnum(s[i]) && flag == in) else if (!isalnum(s[i]) && flag == in)

}s[j] = 0;

}int main(int argc, char *argv)

翻轉字串裡的單詞

給定乙個字串,逐個翻轉字串中的每個單詞。示例 1 輸入 the sky is blue 輸出 blue is sky the 複製 示例 2 輸入 hello world 輸出 world hello 解釋 輸入字串可以在前面或者後面包含多餘的空格,但是反轉後的字元不能包括。複製 示例 3 輸入 a...

翻轉字串裡的單詞

給定乙個字串,逐個翻轉字串中的每個單詞。示例 1 輸入 the sky is blue 輸出 blue is sky the 示例 2 輸入 hello world 輸出 world hello 解釋 輸入字串可以在前面或者後面包含多餘的空格,但是反轉後的字元不能包括。示例 3 輸入 a good ...

翻轉字串裡的單詞

include include 給定乙個字串,逐個翻轉字串中的每個單詞。示例 1 輸入 the sky is blue 輸出 blue is sky the 示例 2 輸入 hello world 輸出 world hello 解釋 輸入字串可以在前面或者後面包含多餘的空格,但是反轉後的字元不能包括...