fork download
  1. #include <iostream>
  2. using namespace std;
  3. #include <bits/stdc++.h>
  4. #include<string>
  5. #include<vector>
  6.  
  7. int main() {
  8. // your code goes here
  9. vector<string>str={"abc","ade","abc"};
  10. vector<vector<int>>g(200000+5,vector<int>(28,0));
  11. int n=3;
  12. vector<int>ans(n,0);
  13. for(int i=n-1;i>=0;i--)
  14. { int count=0;
  15. string s = str[i];
  16. for(int j=0;j<n;j++)
  17. {
  18. int x = int(s[j])-97;
  19. count+=g[j][x]; // tell you freq of x in column j
  20. g[j][x]=g[j][x]+1;
  21. }
  22. ans[i]=count;
  23. }
  24. for(int i=0;i<n;i++)
  25. cout<<ans[i]<<" ";
  26. return 0;
  27. }
Success #stdin #stdout 0.04s 32844KB
stdin
Standard input is empty
stdout
4 1 0