完美世界笔试题。反转数字

#include <iostream>
#include <string>
using namespace std;

int main() {
    char str[10000] = {'0'};
    gets_s(str);
    int len = strlen(str);
    int i = 0, j = 0;
    //删除多余空格
    while (j < len) {
        while (j < len && str[j] == ' ') j++;
        while (j < len && str[j] != ' ' ) {
            str[i++] = str[j++];
        }
        if (i < len) str[i++] = ' ';
        else break;
    }
    while(str[--i] == ' ');
    str[++i] = '\0';
    len = i;

    //反转
    i = 0, j = len - 1;
    while (i < j) {
        char temp = str[i];
        str[i++] = str[j];
        str[j--] = temp;
    }

    //数字反转
    i = 0, j = 0;
    while (j < len) {
        while (j < len && str[j] != ' ')j++;
        j--;
        while (i < j) {
            char temp = str[i];
            str[i++] = str[j];
            str[j--] = temp;
        }
        while (i < len && str[i] != ' ')i++; i++;
        while (j < len && str[j] != ' ')j++; j++;
    }
    cout << str << endl;
    system("pause");
    return 0;
}

#C++工程师#
全部评论
我直接用vector存储输入然后逆序输出了。。。
点赞 回复 分享
发布于 2017-09-27 00:12
我也是这个,血崩
点赞 回复 分享
发布于 2017-09-26 23:10
#include <iostream> #include <vector> #include <string> using namespace std; int main() {     vector<string> s;     string in;     while (cin >> in)     {         s.insert(s.begin(), in);     }     for (vector<string>::const_iterator i = s.begin(); i != s.end(); i++)     {         cout << *i;         if (i+1 != s.end())         {             cout << " ";         }     }     system("pause");     return 0; }
点赞 回复 分享
发布于 2017-09-26 23:03
然而笔试并没有做出来。。哎。。心累。。
点赞 回复 分享
发布于 2017-09-26 22:25

相关推荐

不愿透露姓名的神秘牛友
07-24 13:36
点赞 评论 收藏
分享
程序员小白条:你是沟通了900个,不是投了900份简历,你能投900份,意味着对面都要回复你900次,你早就找到实习了,没亮点就是这样的,别局限地区,时间投的也要早,现在都要7月了
点赞 评论 收藏
分享
仁者伍敌:牛子这些人还会点一个自动回复,boss都不带回复的
点赞 评论 收藏
分享
07-23 11:23
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
7
分享

创作者周榜

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