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

#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

相关推荐

06-18 15:03
门头沟学院 Java
至少实习看起来比去年好?问了下群里的同学和身边的同学,人均有offer。有的还有好几个大厂offer
菜鸟1973:上一年暑期也是人均大厂实习offer,结果秋招跟不招人一样,大部分都转正了
点赞 评论 收藏
分享
程序员牛肉:这一眼假啊,基本上都是骗人的,不然就涉及到职位贪腐了,就像之前华为的OD事件,看你运气好不好了
点赞 评论 收藏
分享
05-12 11:09
已编辑
门头沟学院 后端
已注销:没必要放这么多专业技能的描述。这些应该是默认已会的,写这么多行感觉在凑内容。项目这块感觉再包装包装吧,换个名字,虽然大家的项目基本都是网上套壳的,但是你这也太明显了。放一个业务项目,再放一个技术项目。技术项目,例如中间件的一些扩展和尝试。
点赞 评论 收藏
分享
评论
点赞
7
分享

创作者周榜

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