So let's say I have an array, 1 2 1 2 3 4 2 1
and I want to store all the (arr[i], arr[i-1)
such that arr[i] != arr[i-1]
as a pair in unordered_map for counting these pairs.
For e.g.
(1, 2) -> 2
(2, 3) -> 1
(3, 4) -> 1
(4, 2) -> 1
(2, 1) -> 1
So the syntax I tried,
unordered_map<pair<int, int>, int> umap;
int temp;
cin>>temp;
arr[i]=temp;
for (int i=1; i< n; i++){
cin>>temp;
arr[i]=temp;
umap[(arr[i-1], arr[i])]++;
}
Next thing, I also tried with proper definition.
unordered_map<pair<int, int>, int> umap;
cin>>temp;
arr[i]=temp;
for (int i=1; i< n; i++){
cin>>temp;
arr[i]=temp;
pair<int, int> p(arr[i-1], arr[i]);
umap[p]++;
}
Can anybody please help me get the right syntax?