fork download
  1. #include<iostream>
  2. #include<cstdio>
  3. //length, compare, substring finding, delete, insert, replace, reverse
  4. using namespace std;
  5.  
  6. int Length(string s)
  7. {
  8. int len = 0;
  9. for(int i=0;s[i]!='\0';i++)
  10. {
  11. len++;
  12. }
  13. return len;
  14. }
  15.  
  16. int Compare(string s1, string s2)
  17. {
  18. int lens1 = Length(s1);
  19. int lens2 = Length(s2);
  20.  
  21. if(lens1 == lens2)
  22. {
  23. for(int i=0;i<lens1;i++)
  24. {
  25. if(s1[i] == s2[i])
  26. continue;
  27. else
  28. {
  29. if(s1[i] < s2[i])
  30. {
  31. return 1;
  32. }
  33. else
  34. {
  35. return -1;
  36. }
  37. }
  38. }
  39. return 0;
  40. }
  41. else
  42. {
  43. if(lens1 < lens2)
  44. {
  45. for(int i=0;i<lens1;i++)
  46. {
  47. if(s1[i] == s2[i])
  48. {
  49. continue;
  50. }
  51. else
  52. {
  53. if(s1[i] < s2[i])
  54. {
  55. return 1;
  56. }
  57. else
  58. {
  59. return -1;
  60. }
  61. }
  62. }
  63. return 1;
  64. }
  65. else
  66. {
  67. for(int i=0;i<lens2;i++)
  68. {
  69. if(s1[i] == s2[i])
  70. {
  71. continue;
  72. }
  73. else
  74. {
  75. if(s1[i] < s2[i])
  76. {
  77. return 1;
  78. }
  79. else
  80. {
  81. return -1;
  82. }
  83. }
  84. }
  85. return -1;
  86. }
  87. }
  88. }
  89.  
  90. int main()
  91. {
  92. string str1, str2;
  93. cin>>str1>>str2;
  94. cout<<Compare(str1,str2);
  95. }
Success #stdin #stdout 0.01s 5304KB
stdin
Standard input is empty
stdout
Standard output is empty