fork download
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. int ft_strcmp(string str1, string str2)
  6. {
  7. int s = 0;
  8. bool flag = true;
  9. int count= 0;
  10. while(flag && str1[s] && str2[s])
  11. {
  12. if(str1[s] == str2[s]){
  13. count++;
  14. s++;
  15. }
  16. else
  17. break;
  18. }
  19. return (count);
  20. }
  21.  
  22. int main()
  23. {
  24. int n1 = 0, n2 = 0;
  25. int ar1 = 0, ar2 = 0;
  26. cin >> n1 >> n2;
  27. string str[n1];
  28. int len = n1;
  29. int i = 0;
  30. int lol = 0;
  31. while(n1--)
  32. {
  33. cin >> str[i];
  34. if(str[i].length() > 200000)
  35. return(0);
  36. i++;
  37. }
  38. while(n2--)
  39. {
  40. cin >> ar1 >> ar2;
  41. if((ar1 < 1 || ar1 > 200000 ) || (ar2 < 1 || ar2 > 200000 ))
  42. return (0);
  43. lol = ft_strcmp(str[ar1 -1] , str[ar2 -1]);
  44. cout << lol << endl;
  45. }
  46. }
Success #stdin #stdout 0.01s 5312KB
stdin
4 5
ababa
aba
abcd
bbbb
1 2
1 3
1 4
2 3
3 4
stdout
3
2
0
2
0