Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C++
#include<iostream>
#include<map>
using namespace std;
int main(){
	int k,t,n,m,arr[510][510];
	map<int,int>maps;
	cin>>t;
	while(t--){
		cin>>n>>m;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				cin>>k;
				maps[k]=j;
			}
		}
		for(int i=1;i<=m;i++){
			for(int j=1;j<=n;j++){
				cin>>k;
				arr[j][maps[k]]=k;
			}
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				cout<<arr[i][j]<<" ";
			}cout<<endl;
		}
	}
}


What I have tried:

i couldn't understand the assigning of map.how can we change the values of key in pair?
Posted
Updated 24-Jan-21 20:42pm
v2

Keys are not allowed to change in map. The elements (consisted of key-value pairs) are ordered in a binary tree. If the key is changed, its order (or position) in the tree should be updated. This is why the key in the key-value pair is constant. But you can delete and insert a new element.
 
Share this answer
 
v2
Comments
CPallini 25-Jan-21 2:40am    
5.
You might also have a look at the documentation: map - C++ Reference[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900