救救孩子吧,实在debug不出来了
  • 板块学术版
  • 楼主UnderDogStar
  • 当前回复2
  • 已保存回复2
  • 发布时间2020/12/21 21:44
  • 上次更新2023/11/5 05:49:32
查看原帖
救救孩子吧,实在debug不出来了
290570
UnderDogStar楼主2020/12/21 21:44

T160510 D - 终端

思路是利用两个mapmap映射

一个用来判断是否被删除

一个用来判断当前字符串在strstr数组的位置

#include <bits/stdc++.h>
using namespace std;
#define MaxN 1010
string str[MaxN];
map <string,bool> used;
map <string,int> idx;
int cnt;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int n;
    cin >> n;
    for(int i=1; i<=n; i++){
        string work , xxx , yyy;
        cin >> work;
        if( work == "touch" ){
            cin >> xxx;
            if( !used[xxx] ){
                ++cnt;
                str[cnt]=xxx;
                idx[xxx]=cnt;
                used[xxx]=true;
            }
        }
        else if( work == "rm" ){
            cin >> xxx;
            if( used[xxx] ){
                used[xxx]=false;
            }
        }
        else if( work == "rename" ){
            cin >> xxx >> yyy;
            if( used[xxx] && !used[yyy] ){
                str[idx[xxx]]=yyy;
                used[xxx]=false;
                used[yyy]=true;
            }
        }
        else{
            for(int i=1; i<=cnt; i++){
                if( used[str[i]] ){
                    cout << str[i] << '\n';
                }
            }
        }
    }
    return 0;
}

2020/12/21 21:44
加载中...