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