fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. inline bool my_strcmp1(const char* _s, const char* _d)
  5. { while(*_s || *_d)
  6. { if(*_s++ != *_d++) return true;
  7. }
  8. return false;
  9. }
  10.  
  11.  
  12. bool stringCompare(const char* s1, const char* s2) {
  13. for(;;) {
  14. if (*s1 != *s2) return false;
  15. if (*s1 == 0 || *s2 == 0) return true;
  16. ++s1;
  17. ++s2;
  18. }
  19. }
  20.  
  21. int _strcmp(const char* a, const char* b)
  22. {
  23. int result = (a == nullptr)
  24. ? ((b == nullptr)
  25. ? 0 : 1)
  26. : ((b == nullptr)
  27. ? -1: 2);
  28.  
  29. if(result == 2)
  30. {
  31. while(*a != '\0' && *a++ == *b++){}
  32. --a;
  33. --b;
  34. result = ((*a == *b) ? 0 : ((*a < *b) ? -1 : 1));
  35. }
  36.  
  37. return result;
  38. }
  39.  
  40. int main()
  41. {
  42. // https://g...content-available-to-author-only...v.ru/flame/forum/?id=233418&page=7
  43. cout<<((my_strcmp1("Клапауций", "Жлапауций")) ? "true" : "false")<<endl;
  44. cout<<((my_strcmp1("Клапауций", "КлапауцийРукожоп")) ? "true" : "false")<<endl;
  45. cout<<((my_strcmp1("Клапауций!", "КлапауцийРукожоп")) ? "true" : "false")<<endl;
  46. cout<<((my_strcmp1("Клапауций", "Клапауций")) ? "true" : "false")<<endl;
  47. cout<<"------------------------------"<<endl;
  48. cout<<((stringCompare(nullptr, "ТарасРукожоп")) ? "true" : "false")<<endl;
  49. cout<<"------------------------------"<<endl;
  50. cout<<((_strcmp("Клапауций", "Жлапауций")==0) ? "true" : "false")<<endl;
  51. cout<<((_strcmp("Клапауций", "ЖлапауцийРукожоп")==0) ? "true" : "false")<<endl;
  52. cout<<((_strcmp("Клапауций!", "ЖлапауцийРукожоп")==0) ? "true" : "false")<<endl;
  53. cout<<((_strcmp("Клапауций", "Клапауций")==0) ? "true" : "false")<<endl;
  54.  
  55.  
  56. return 0;
  57. }
Runtime error #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
true
true
true
false
------------------------------