-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpairsOfPalindrome.cpp
33 lines (29 loc) · 1.01 KB
/
pairsOfPalindrome.cpp
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
#include <bits/stdc++.h>
#define ll long long
using namespace std;
map<ll, ll>m;
int main()
{
ll n;
cin >> n;
//Input how many pair will be given*/
ll sum = 0, ans = 0, flag = 0;
for (ll i = 0; i < n; i++) {
string str;
cin >> str;
ll c = 0;
/*After taking string input then make a bitmsk for that string*/
for (ll j = 0; j < str.size(); j++) {
c ^= (1 << (str[j] - 'a'));
}
ans += m[c];/*Here we are just adding same string palindrome pair number*/
/*After making bitmask of c ,then we are searching for a string which can be make palindrome with c.Basically here we
are searching every combination that can be palindrome with c.*/
for (ll j = 0; j < 26; j++) {
ans += (m[c ^ (1 << j)]);
}
m[c]++;
}
cout << ans << endl;
return 0;
}