zoukankan      html  css  js  c++  java
  • 集训final D STL中string的应用

    #include<iostream>
    #include<string>
    #include<vector>
    #include<cstdio>
    using namespace std;
    
    int main()
    {
        int n;
        while(cin>>n)
        {
            vector<string>s;
            while(!s.empty())
            {
                s.pop_back();
            }
            while(n--)
            {
                string cmd;
                cin>>cmd;
                if(cmd=="cd")
                {
                    string path;
                    cin>>path;
                    int pos=path.find("/");
                    if(pos==0)
                    {
                        while(!s.empty())
                        {
                            s.pop_back();
                        }
                        path.erase(0,1);
                    }
                    pos=path.find("/");
                    while(pos!=string::npos)
                    {
                        if(path.substr(0,pos)=="..")
                        {
                            if(!s.empty())
                            {
                                s.pop_back();
                            }
                        }else
                        {
                            s.push_back(path.substr(0,pos));
                        }
                        path.erase(0,pos+1);
                        pos=path.find("/");
                    }
                    if(path.length()!=0)
                    {
                        if(path=="..")
                        {
                            if(!s.empty())
                            {
                                s.pop_back();
                            }
                        }else
                        {
                            s.push_back(path);
                        }
                    }
                    
                    /*
                    string path;
                    cin>>path;
                    int pos=path.find("/");
                    if(pos!=0)
                    {
                        int pos_next=path.find("/",pos+1);
                        string pname=substr(pos,pos_next-pos-1);
                        if(pname=="..")
                        {
                            if(!s.empty())
                            {
                                s.pop();
                            }
                        }
                        while(s.fornt()!=pname)
                        {
                            
                        }
                    }
                    while(pos!=string::npos)
                    {
                        int pos_next=path.find("/",pos+1);
                        if(pos_next!=string::npos)
                        {
                            string pname=substr(pos,pos_next-pos-1);
                            if(pname=="..")
                            {
                                if(!s.empty())
                                {
                                    s.pop_back();
                                }
                            }
                        }
                    }*/
                }else if(cmd=="pwd")
                {
                    int i;
                    cout<<"/";
                    for(i=0;i<=int(s.size())-1;i++)
                    {
                        cout<<s[i]<<"/";
                    }
                    cout<<endl;
                }
            }
        }
        return 0;
    }
    

      

  • 相关阅读:
    学习进度第七周
    NABCD---生活日历
    学习进度第六周
    人月神话阅读笔记(3)
    人月神话阅读笔记(2)
    人月神话阅读笔记(1)
    石家庄地铁查询(双人项目)
    学习进度第五周
    学习进度第四周
    返回一个整数数组中最大子数组的和。(续2)---二维数组
  • 原文地址:https://www.cnblogs.com/cj695/p/2623283.html
Copyright © 2011-2022 走看看