//旋转字符串,将"I am a student."转换为"student. a am I" #include <string> #include <iostream> using namespace std; string rotateString(string str) { string result = ""; string temp = ""; int len = str.size(); for (int i = 0; i < len; i++) { if (str[i] != ' ') temp += str[i]; else { if (result.size()) { result = temp + " " + result; } else result = temp + result; temp = ""; } } result = temp +" "+result; return result; } int main() { string str = "I am a student."; cout<<rotateString(str); system("pause"); return 0; }
点赞 评论

相关推荐

03-12 15:35
嘉应学院 Python
快说谢谢牛牛精灵:说不定就是下一个寒武纪!
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务