fork download
  1. #include <stdio.h>
  2.  
  3. int compare(char *str1, char *str2){
  4.  
  5. int ret = 0;
  6. long str1_size = 0;
  7. long str2_size = 0;
  8.  
  9. while(str1[str1_size] != '\0'){
  10. str1_size++;
  11. }
  12.  
  13. while(str2[str2_size] != '\0'){
  14. str2_size++;
  15. }
  16.  
  17. if(str1_size>str2_size){
  18. ret = 1;
  19. }
  20. else if(str1_size==str2_size){
  21. for(long i = str1_size-1; i>0; i--){
  22. int digit1 = str1[i] - '0';
  23. int digit2 = str2[i] - '0';
  24. if(digit1>digit2){
  25. ret =1;
  26. break;
  27. }
  28. }
  29. }
  30.  
  31. return ret;
  32. }
  33.  
  34.  
  35. int main(void) {
  36. // your code goes here
  37.  
  38. printf("Pass %d\n", compare("10","5"));
  39. printf("Pass %d\n", compare("5","10"));
  40. printf("Pass %d\n", compare("986","976"));
  41. printf("Pass %d\n", compare("976","986"));
  42. printf("Pass %d\n", compare("9765484986545645689798476546547","9765484986545645689798476546546"));
  43. printf("Pass %d\n", compare("9765484986545645689798476546546","9765484986545645689798476586546"));
  44. printf("Pass %d\n", compare("0","9765484986545645689798476586546"));
  45.  
  46. return 0;
  47.  
  48.  
  49. }
  50.  
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
Pass 1
Pass 0
Pass 1
Pass 0
Pass 1
Pass 0
Pass 0