fork download
  1. #include <iostream>
  2. using namespace std;
  3. #include <bits/stdc++.h>
  4. #include<string>
  5. #include<vector>
  6. int match_count(string &a,string &b)
  7. { int count=0;
  8. int n = min(a.size(),b.size());
  9. for(int i=0;i<n;i++)
  10. {
  11. if(a[i]==b[i])
  12. count++;
  13.  
  14. }
  15.  
  16. return count;
  17. }
  18. int main() {
  19. // your code goes here
  20. vector<string>str={"abc","ade","abc"};
  21. int n=3;
  22. vector<int>ans(n,0);
  23.  
  24.  
  25. for(int i=n-1;i>=0;i--)
  26. {
  27. int res=0;
  28. if(i==n-1)
  29. {
  30. res=0;
  31. }
  32. else
  33. {
  34. for(int j=i+1;j<n;j++)
  35. {
  36. res+=match_count(str[i],str[j]);
  37. }
  38. }
  39. ans[i]=res;
  40. }
  41.  
  42. for(int i=0;i<n;i++)
  43. {
  44. cout<<ans[i]<<" ";
  45. }
  46.  
  47. return 0;
  48. }
Success #stdin #stdout 0s 5252KB
stdin
3
stdout
4 1 0