Advertisement
erfanul007

LOJ 1114

Sep 11th, 2021
815
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. map< string, int > mp;
  5.  
  6. int main(){
  7.     #ifdef ERFANUL007
  8.         clock_t tStart = clock();
  9.         freopen("input.txt", "r", stdin);
  10.         freopen("output.txt", "w", stdout);
  11.     #endif
  12.  
  13.     int t, cs = 0;
  14.     cin >> t;
  15.  
  16.     while(t--){
  17.         cout << "Case " << ++cs << ":\n";
  18.         mp.clear();
  19.  
  20.         int n;
  21.         cin >> n;
  22.         for(int i=0; i<n; i++){
  23.             string s;
  24.             cin >> s;
  25.             if(s.size() > 2) sort(s.begin()+1, s.end()-1);
  26.             //cout << s << '\n';
  27.             mp[s]++;
  28.         }
  29.         int q;
  30.         cin >> q;
  31.         getchar();
  32.  
  33.         for(int i=0; i<q; i++){
  34.             string line, s;
  35.             getline(cin, line);
  36.             long long ans = 1;
  37.  
  38.             stringstream ss(line);
  39.  
  40.             while(ss >> s){
  41.                 if(s.size() > 2) sort(s.begin()+1, s.end()-1);
  42.                 //cout << s << '\n';
  43.                 ans *= mp[s];
  44.             }
  45.             cout << ans << '\n';
  46.         }
  47.  
  48.     }
  49.  
  50.  
  51.     #ifdef ERFANUL007
  52.         fprintf(stderr, ">>> Runtime : %.9f\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
  53.     #endif
  54.  
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement