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