fork download
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. #include <string.h>
  4. int min(int a, int b){
  5. return a < b ? a : b;
  6. }
  7. int distance(char str1[], char str2[], int index1, int index2){
  8.  
  9. if (index1 < 0) {
  10. return index2 + 1;
  11. }
  12. if (index2 < 0) {
  13. return index1 + 1;
  14. }
  15.  
  16. if(str1[index1] == str2[index2]){
  17. return distance(str1, str2, index1 - 1, index2 - 1);
  18. }
  19. else{
  20. return min(distance(str1, str2, index1 - 1, index2), distance(str1, str2, index1, index2 - 1)) + 1;
  21. }
  22. }
  23. int main()
  24. {
  25. char str[100][11];
  26. int i=0;
  27. while(scanf("%s", str[i]) != EOF){
  28. i++;
  29. }
  30. int min_distance = 1000000000;
  31. int min_index1 = 0;
  32. int min_index2 = 0;
  33. for(int j = 0; j < i; j++){
  34. for(int k = j + 1; k < i; k++){
  35. if(distance(str[j], str[k], strlen(str[j]) - 1, strlen(str[k]) - 1) < min_distance){
  36. int min = min_distance;
  37. min_distance = distance(str[j], str[k], strlen(str[j]) - 1, strlen(str[k]) - 1);
  38. min_index1 = j;
  39. min_index2 = k;
  40. }
  41. }
  42. }
  43. printf("%d %d %d", min_distance, min_index1 + 1, min_index2 + 1);
  44. }
Success #stdin #stdout 0s 5264KB
stdin
BAADDDBEAB
BAADDDBEDB
stdout
2 1 2