20分,求助

P3613 【深基15.例2】寄包柜

shenyeting @ 2024-01-30 19:06:59

#include<bits/stdc++.h>
using namespace std;
map<pair<int,long long>,int> m;
int main(){
    int a,b;
    cin>>a>>b;
    for(int i=0;i<b;i++){
        int x;
        cin>>x;
        if(x==1){
            int aa,bb,cc;
            cin>>aa>>bb>>cc;
            m.insert({{aa,bb},cc});
        }
        if(x==2){
            int dd,ee;
            cin>>dd>>ee;
            auto it=m.find({dd,ee});
            if (it != m.end()) {
                cout << it->second << endl;  
            }
        }
    }
}

样例能过


by love_ovo @ 2024-01-31 23:33:03

当 cc == 0 时是清空操作,你少了程序


by shenyeting @ 2024-02-01 11:10:06

栓Q,AC了


by kds2012 @ 2024-03-10 08:41:26

发一种其他思路看看

#include<bits/stdc++.h> 
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    vector< vector<int> > l(n+1);
    int tmp;
    while(m--){
        int i,j,k;
        cin>>tmp;
        if(tmp==1){
            cin>>i>>j>>k;
            if(l[i].size()<j+1){
                l[i].resize(j+1);
            }
            l[i][j]=k;
        }
        else{
            cin>>i>>j;
            cout<<l[i][j]<<endl;
        }
    }
    return 0;
}

|