代码求调,RE
查看原帖
代码求调,RE
893114
denghuolanshan_1004楼主2023/8/13 15:56
#include<iostream>
#include<cstring>
using namespace std;
int main(){
    int n;
    string file[1001],ord,first,second;//ord是order 的简写
    bool create[1001];
    bool can=1;
    int cnt;
    cin>>n;
    
    //start
    for(int i=0;i<n;i++){
        cin>>ord;
        //touch
        if (ord=="touch"){
            cin>>first;
            for(int j=0;j<cnt;j++){
                if (file[j]==first&&create[j]==true)can=0;break;
            }
            if (can==1){
                file[cnt]=first;
                create[cnt]=true;
                cnt++;
            }
            can=1;
        }
        
        //rm
        if (ord=="rm"){
            cin>>first;
            for(int j=0;j<cnt;j++){
                if (file[j]==first&&create[j]==true)create[j]==false;break;
            }
        }
        
        //rename
        if (ord=="rename"){
            cin>>first>>second;
            for (int j=0;j<cnt;j++){
                if (file[j]==first)file[j]=second;break;
            }
        }
        
        //ls
        if (ord=="ls"){
            for(int j=0;j<cnt;j++){
                if (create[j]==true)cout<<file[j]<<endl;
            }
        }
    }
    return 0;
}

具体判定内容:Runtime Error. Received signal 11: Segmentation fault with invalid memory reference.

2023/8/13 15:56
加载中...