为什么上下两个代码一个错一个对的,错的错在哪?
查看原帖
为什么上下两个代码一个错一个对的,错的错在哪?
586704
XZIT20210907149楼主2022/3/29 15:17

###这是对的

#include<bits/stdc++.h>
using namespace std;
#define max 100005
struct locker{
		vector<int> num,k;
		int s;
	}locker1[max];
int main() 
{
	int n,q;
	cin>>n>>q;
	int a,i,j,k;
	for(int h=0;h<q;h++){
		cin>>a;
		if(a==1){
			cin>>i>>j>>k;
			locker1[i].s++;
			locker1[i].num.push_back(j);
			locker1[i].k.push_back(k);
		}
		else{
			cin>>i>>j;
			for(int h=locker1[i].s-1;h>=0;h--){
				if(locker1[i].num[h]==j){
					cout<<locker1[i].k[h]<<endl;
					break;
				}
			}
			
		}
	}
}

###这是错的

#include<bits/stdc++.h>
using namespace std;
#define max 100005
struct locker{
		vector<int> num,k;
	}locker1[max];
int main() 
{
	int n,q;
	cin>>n>>q;
	int a,i,j,k;
	for(int h=0;h<q;h++){
		cin>>a;
		if(a==1){
			cin>>i>>j>>k;
			locker1[i].num.push_back(j);
			locker1[i].k.push_back(k);
		}
		else{
			cin>>i>>j;
			for(int h=0;h<q;h++){
				if(locker1[i].num[h]==j){
					cout<<locker1[i].k[h]<<endl;
					break;
				}
			}
			
		}
	}
}
2022/3/29 15:17
加载中...