大佬帮忙看看,下面这段代码为啥老是段错误呢?本地IDE可以通过示例。 #include <iostream> #include <string> #include <stack> using namespace std; int main() {     ///a/./b/../../c/     string s;     while (cin >> s)     {         string res;         int n = s.size();         stack<string> st;         stack<string> st2;         int start = 0;         int end = 0;         int flag = 0;         while (1)         {             start = s.find_first_of('/', start);             if (start == -1)             {                 st.push(s);                 break;             }             string str;             end = s.find_first_of('/', start + 1);             str = s.substr(start + 1, end - start - 1);             start = end;             if (str == "")             {                 break;             }             if (str == "..")             {                 st.pop();             }             else if (str == ".")             {                 continue;             }             else             {                 st.push(str);             }         }         for (int i = 0; i < st.size();)         {             string top = st.top();             st.pop();             st2.push(top);         }         for (int i = 0; i < st2.size();)         {             string top = st2.top();             cout << "/" << top;             st2.pop();         }         cout << endl;     }     return 0; }
点赞 评论

相关推荐

10-26 13:03
已编辑
门头沟学院 物流经理
在okr拆解的小太阳...:实习待过,我待的部门氛围很好,基本不加班,双休有保证。
投递正浩创新EcoFlow等公司10个岗位
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务