PAT (Basic Level) Practise 的C++实现-1009. 说反话

本文介绍了一种颠倒英语句子中单词顺序的方法,并提供了一个简单的C++程序示例。该程序读取一个包含单词和空格的字符串,然后输出单词顺序颠倒后的句子。

给定一句英语,要求你编写程序,将句中所有单词的顺序颠倒输出。
输入格式:测试输入包含一个测试用例,在一行内给出总长度不超过80的字符串。字符串由若干单词和若干空格组成,其中单词是由英文字母(大小写有区分)组成的字符串,单词之间用1个空格分开,输入保证句子末尾没有多余的空格。

输出格式:每个测试用例的输出占一行,输出倒序后的句子。

输入样例:
Hello World Here I Come
输出样例:

Come I Here World Hello

    #include <iostream>
    #include <vector>
    #include <string>
    #include <cstring>
    using namespace std;
    /* run this program using the console pauser or add your own getch, system("pause") or input loop */

    int main() {
        int i, j;
        string word;
        string wordx;
        vector <string> stc;
        getline(cin, word);
        for (i = 0,j=0; i < word.length(); i++) {
            if (word[i] != ' ') {
                wordx += word[i];
            }
            else {
                stc.push_back(wordx);
                wordx = {};
            }
        }
        stc.push_back(wordx);
        cout<< stc.back();
        stc.pop_back();
        while(!stc.empty()){
        cout<<" "<<stc.back();
        stc.pop_back();
        }
        return 0;
    }

想输入想了半天,发现cin>>不能区分空格和换行,遂放弃,想用strtok,但是没有实现。。。

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project hertzbeat-otel: Compilation fai lure: Compilation failure: [ERROR] 读取C:\Users\DE-LL\.m2\repository\io\opentelemetry\opentelemetry-sdk-logs\1.49.0\opentelemetry-sdk-logs-1.49.0.jar时出错; zip file is empty [ERROR] /F:/Practise/hertzbeat-master/hertzbeat-otel/src/main/java/org/apache/hertzbeat/otel/config/OpenTelemetryLogbackAppenderInstaller.java:[19,1] 无 法访问org.apache.hertzbeat.otel.config [ERROR] ZipException opening "opentelemetry-sdk-logs-1.49.0.jar": zip END header not found [ERROR] /F:/Practise/hertzbeat-master/hertzbeat-otel/src/main/java/org/apache/hertzbeat/otel/config/LogAutoConfiguration.java:[34,8] 无法访问org.apache. hertzbeat.otel [ERROR] ZipException opening "opentelemetry-sdk-logs-1.49.0.jar": zip END header not found [ERROR] /F:/Practise/hertzbeat-master/hertzbeat-otel/src/main/java/org/apache/hertzbeat/otel/config/OpenTelemetryConfig.java:[50,8] 无法访问org.apache.h ertzbeat [ERROR] ZipException opening "opentelemetry-sdk-logs-1.49.0.jar": zip END header not found [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException [ERROR] [ERROR] After correcting the problems, you can resume the build with the command [ERROR] mvn <args> -rf :hertzbeat-otel 解决错误
最新发布
09-02
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值