7-32 说反话-加强版

题目链接:7-32 说反话-加强版

一. 题目

1. 题目

在这里插入图片描述

2. 输入输出样例

在这里插入图片描述

3. 限制

在这里插入图片描述

二、代码

1. 代码实现

str1 = input().split('\n')[0] // 按行获取输入
list_str = str1.split()[::-1] // 按空格分割为字符串组,然后将字符串组逆序
str1 = ' '.join(list_str) // 用空格做分隔符,将字符串组转换为字符串
print(str1) // 打印

2. 提交结果

在这里插入图片描述

三、代码

1. 代码实现

#include <iostream>
#include <string.h>
#include <stack>
using namespace std;

int main(void) {
    string str;
    stack<string> s;
    while (cin >> str) {
        s.push(str); // 入栈
    }
    str = "";
    while (!s.empty()) {
        if (!str.empty()) {
            cout << ' '; // 字符串之间的一个空格
        }
        str = s.top(); // 获取栈顶
        cout << str; // 打印
        s.pop(); // 出栈
    }
    cout << endl;
    return 0;
}

2. 提交结果

在这里插入图片描述

相关推荐

  1. STM<span style='color:red;'>32</span> <span style='color:red;'>7</span>-8

    STM32 7-8

    2024-04-26 23:32:04      40 阅读
  2. 鸡兔同笼问题加强

    2024-04-26 23:32:04       59 阅读
  3. 李白打酒加强(c++实现)

    2024-04-26 23:32:04       28 阅读
  4. 李白打酒加强 -- 题解 c++

    2024-04-26 23:32:04       37 阅读
  5. 题目 2662: 李白打酒加强

    2024-04-26 23:32:04       39 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-26 23:32:04       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-26 23:32:04       101 阅读
  3. 在Django里面运行非项目文件

    2024-04-26 23:32:04       82 阅读
  4. Python语言-面向对象

    2024-04-26 23:32:04       91 阅读

热门阅读

  1. 启动MySQL服务

    2024-04-26 23:32:04       37 阅读
  2. 38 事件

    2024-04-26 23:32:04       37 阅读
  3. 【MySQL面试题】经典面试题之“b+树”

    2024-04-26 23:32:04       40 阅读
  4. Nest.js项目小结2

    2024-04-26 23:32:04       35 阅读
  5. 机器学习模型保存和导出pmml文件(python代码)

    2024-04-26 23:32:04       38 阅读
  6. 贪吃蛇项目实践!(下)

    2024-04-26 23:32:04       44 阅读