B1009 说反话 重要 P65下

//B1009 说反话 重要 P65下
#include <iostream>
#include <string>
using namespace std;
int main(){
    string s;
    getline(cin,s);
    while(s.length() > 0){
        int i = s.rfind(' '); //从右向左找
        if(i != string::npos){
            cout<<s.substr(i+1)<<" ";
            string temp = s.substr(0,i);
            s = temp;
        }else{
            cout<<s<<endl;
            s="";
        }

    }


    return 0;
}
C:
#include <stdio.h>
#include <string.h>
#define maxSize 100
void reverse(int left,int right,char a[]){
    for(int i=left,j=right;i<j;++i,--j){
        char temp;
        temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }
}


int main() {
    char str[maxSize];
    gets(str);//warning: this program uses gets(), which is unsafe.
    int len = strlen(str);
    reverse(0,len-1,str);
    int i=0,j=0;
    while(1){
        while (str[j] != ' ' && str[j] != '\0') ++j;
        reverse(i,j-1,str);
        if(str[j] == '\0') break;
        ++j;
        i = j;

    }
    puts(str);
    return 0;
}


全部评论

相关推荐

11-11 16:40
已编辑
门头沟学院 人工智能
不知道怎么取名字_:这个有点不合理了,相当于已经毕业了,但还是没转正,这不就是白嫖
点赞 评论 收藏
分享
牛至超人:把哈工大,再加大加粗,看见闪闪发光的哈工大字样,面试官直接流口水
投递字节跳动等公司7个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务