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

#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++工程师#
全部评论
然而笔试并没有做出来。。哎。。心累。。
点赞 回复
分享
发布于 2017-09-26 22:25
#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 23:10
我直接用vector存储输入然后逆序输出了。。。
点赞 回复
分享
发布于 2017-09-27 00:12

相关推荐

头像
04-07 00:10
点赞 评论 收藏
转发
点赞 7 评论
分享
牛客网
牛客企业服务