其他分享
首页 > 其他分享> > 传智杯 ——终端

传智杯 ——终端

作者:互联网

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

int main(void)
{
    int n;
    cin >> n;
    string opr;
    string en;
    string gaizheng;
    vector<string> file;

    for (int i = 0; i < n; i++)
    {
        cin >> opr;
        if (opr == "touch")
        {
            cin >> en;
            int q = 0;
            for (auto k = file.begin(); k != file.end(); k++)
            {
                if (*k == en)
                {
                    q = 1;
                    break;
                }
            }
            if(q == 0)
            file.push_back(en);
        }

        if (opr == "rm")
        {
            cin >> en;
            for (auto k = file.begin(); k != file.end(); k++)
            {
                if (*k == en)
                {
                    file.erase(k);
                    break;
                }
            }
        }

        if (opr == "ls")
        {
            for (auto k = file.begin(); k != file.end(); k++)
            {
                cout << *k << endl;
            }
        }

        if (opr == "rename")
        {
            cin >> en;
            cin >> gaizheng;
            for (auto k = file.begin(); k != file.end(); k++)
            {
                if (*k == en)
                {
                    *k = gaizheng;
                }
            }
        }
    }
    return 0;
}

 

标签:传智杯,en,opr,++,cin,int,终端,file
来源: https://www.cnblogs.com/loliconsk/p/14274117.html