fork download
  1. #include<string>
  2. #include<limits>
  3. #include<iostream>
  4. using namespace std;
  5. int main()
  6. {
  7. char targetString[100] = "fox";
  8. char targetString2[100] = "the";
  9. char strings[100];
  10. cin>>strings;
  11. double minDistance = std::numeric_limits<double>::infinity();
  12. for (int x = 0; x < strlen(strings); x++)
  13. {
  14. if (strings[x].equals(targetString))
  15. {
  16. for (int y = x; y < strlen(strings); y++)
  17. {
  18. if (strings[y] == (targetString2))
  19. {
  20. if (minDistance > (y - x))
  21. {
  22. minDistance = y - x;
  23. }
  24. }
  25. }
  26. for (int y = x; y >= 0; y--)
  27. {
  28. if (strings[y] == (targetString2))
  29. {
  30. if (minDistance > (x - y))
  31. {
  32. minDistance = x - y;
  33. }
  34. }
  35. }
  36. }
  37. }
  38. cout<<minDistance;
  39. return 0;
  40. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
the quick the brown fox the
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:12:35: error: ‘strlen’ was not declared in this scope
 for (int x = 0; x < strlen(strings); x++)
                                   ^
prog.cpp:14:17: error: request for member ‘equals’ in ‘strings[x]’, which is of non-class type ‘char’
  if (strings[x].equals(targetString))
                 ^~~~~~
prog.cpp:18:36: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
    if (strings[y] == (targetString2))
                                    ^
prog.cpp:28:36: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
    if (strings[y] == (targetString2))
                                    ^
stdout
Standard output is empty