C++:将输入的一段句子倒序重排

    xiaoxiao2021-04-14  49

    我写的程序是已知句子中单词的个数的,如果有人会不用知道单词个数就可以实现的,麻烦指点一下,新手

    #include "stdafx.h"

    #include<iostream> #include<string> const int ArSzie = 10; int main() { int n; std::cin >> n; std::string word[ArSzie]; for (int i = 0; i < n; i++) std::cin >> word[i]; for (int i = 0, j = n - 1; i <n / 2; i++, j--) { std::string t; t=word[i]; word[i] = word[j]; word[j] = t; } for (int i = 0; i < n; i++) std::cout << word[i] << " ";     return 0; }
    转载请注明原文地址: https://ju.6miu.com/read-670564.html

    最新回复(0)