fork(18) download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define MOD 1e9+7
  4. #define FastIO ios_base :: sync_with_stdio(false) ; cin.tie(NULL) ; cout.tie(NULL) ;
  5.  
  6. using namespace std ;
  7.  
  8. void solve()
  9. {
  10. unordered_map < string , int > mp ;
  11.  
  12. vector < string > a ;
  13.  
  14. string b , c ;
  15.  
  16. int n , q ;
  17.  
  18. cin >> n ;
  19.  
  20. while(n--) {
  21.  
  22. cin >> b ;
  23. sort(b.begin() , b.end()) ;
  24. mp[b]++ ;
  25. }
  26.  
  27. cin >> q ;
  28.  
  29. while(q--) {
  30. cin >> c ;
  31. sort(c.begin() , c.end());
  32. cout << mp[c] << "\n" ;
  33. }
  34.  
  35. }
  36.  
  37. int main()
  38. {
  39. FastIO
  40.  
  41. int testcases = 1;
  42.  
  43. cin >> testcases ;
  44.  
  45. while(testcases--) {
  46. solve() ;
  47. }
  48. return 0 ;
  49. }
Success #stdin #stdout 0s 4244KB
stdin
1
12
hack
a
rank
khac
ackh
kran
rankhacker
a
ab
bo
stairs
raits
5
a
nark
bs
hack
stair
stdout
2
2
0
3
1