fork download
  1. #include <iostream>
  2. #include<bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. // your code goes here
  8. int n;
  9. cin>>n;
  10. vector<string> arr(n);
  11. for(int i=0;i<n;i++){
  12. cin>>arr[i];
  13.  
  14. }
  15.  
  16. vector<vector<int>> hashing(26,vector<int>(100000+1,0));
  17. vector<int> ans(n,0);
  18.  
  19.  
  20. for(int i=n-1;i>=0;i--){
  21. int c=0;
  22. for(int j=0;j<arr[i].size();j++){
  23. c=c+hashing[arr[i][j]-'a'][j];
  24. hashing[arr[i][j]-'a'][j]++;
  25.  
  26. }
  27. ans[i]=c;
  28.  
  29. }
  30.  
  31. for(int i=0;i<n;i++){
  32. cout<<ans[i]<<" ";
  33.  
  34. }
  35. return 0;
  36. }
Success #stdin #stdout 0.01s 13756KB
stdin
3
abc ade abc
stdout
4 1 0