最简洁的代码,没有之一!

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

wangzhih @ 2022-01-01 20:49:28

STL大法好

#include<bits/stdc++.h>
using namespace std;
int n,q,oper,i,j,k;//oper操作符 
map<int,map<int,int> > a;//"> >"用于防止误判位操作 
int main() {
    cin>>n>>q;
    while(q--){//重复q次 
        cin>>oper>>i>>j;
        if(oper-1) cout<<a[i][j]<<endl;//读 
        else cin>>k,a[i][j]=k;//存
    }
    return 0;
}

by Phartial @ 2022-01-01 21:00:47

@Ew_Cors 对


by Ew_Cors @ 2022-01-01 21:02:45

@wsfxk 好趴qaq


by Phartial @ 2022-01-01 21:06:00

更短的:

#include<bits/stdc++.h>
using namespace std;int q,o,i,j;map<int,int>a[100001];main(){cin>>q>>q;while(q--)cin>>o>>i>>j,o-1?(cout<<a[i][j]<<endl,0):(cin>>a[i][j],0);}

by Ew_Cors @ 2022-01-01 21:14:46

@wsfxk Orz


by xhgua @ 2022-01-02 07:44:02

压行大法好


by Hisaishi_Kanade @ 2022-02-10 14:34:31

@Ew_Cors 会的,DEVC++会CE 理由:

[Error] operands to ?: have different types 'const char*' and 'int'

by wangzhih @ 2022-07-11 13:06:41

#include<bits/stdc++.h>
using namespace std;
int q,o,i,j;
map<int,int>a[100001];
main(){
    cin>>q>>q;
    while(q--)
        cin>>o>>i>>j,o-1?(cout<<a[i][j]<<endl,0):(cin>>a[i][j],0);
}

by X_WUperformence @ 2022-08-29 22:42:52

map里定map~高级~


上一页 |