-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpair_map.cpp
More file actions
40 lines (35 loc) · 931 Bytes
/
pair_map.cpp
File metadata and controls
40 lines (35 loc) · 931 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
///string s, store pairwise character in a map
#include<bits/stdc++.h>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
using namespace std;
int main()
{
//sync;
int tc;
cin>>tc;
while(tc--){
int n;
string s;
cin>>n>>s;
//map<string,int> mp;
// for(int i=0; i<n-1; i++){
// string p = "";
// p += s[i];
// p += s[i+1];
// mp[p]++;
// }
//
// for(auto it=mp.begin(); it!=mp.end(); it++){
// cout<< it->first<< " "<< it->second << "\n";
// }
map<pair<char,char>,int> m;
for(int i=0; i<n; i++){
m[{s[i],s[i+1]}]++;
}
for(auto it=m.begin(); it!=m.end(); it++){
cout<< it->first.first << it->first.second << " "<< it->second<<endl;
}
}
return 0;
}