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. for(int i = 0 ; i<n ; i++){
  10. cin>>arrs[i];
  11. }
  12. vector<int>count(n);
  13. for(int i =0 ; i<n;i++){
  14. int c= 0 ;
  15. int k = i+1 ;
  16. while(k<n){
  17. //compare arrs[i] and arrs[k]
  18. int l = min (arrs[i].size(),arrs[k].size());
  19. for(int j= 0 ; j <l;j++){
  20. if(arrs[k][j]==arrs[i][j])c++;
  21. }
  22. k++;
  23. }
  24. count[i]=c;
  25.  
  26. }
  27. int i = 0 ;
  28. while(i<n){
  29. cout<<count[i]<<" ";
  30. i++;
  31. }
  32. return 0;
  33. }
Success #stdin #stdout 0.01s 5316KB
stdin
3 
abc ade abc
stdout
4 1 0