Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.66 KB | None | 0 0
  1. /*********************************************************************\
  2.       |        _            ____     _          _           ____      |
  3.      / \      | \     |    /    \   | \     |  | \     |   /    \     |
  4.     /   \     |  \    |   /      \  |  \    |  |  \    |  /      \    |
  5.    /-----\    |   \   |  |        | |   \   |  |   \   | |        |   |
  6.   /       \   |    \  |   \      /  |    \  |  |    \  |  \      /    |
  7.  /         \  |     \_|    \____/   |     \_|  |     \_|   \____/     |
  8.                                                                       |
  9.                                                                       |
  10.     codeforces: safayet007 || codechef: saf1ano2_1234                 |
  11.     BUET EEE '17                                                      |
  12.                                                                       |
  13. **********************************************************************/
  14.  
  15.  
  16. #include <stdio.h>
  17.  
  18. int strrlen(char *str)
  19. {
  20.     int length = 0, i;
  21.     for(i = 0; *(str + i); i++)
  22.     {
  23.         length++;
  24.     }
  25.     return length;
  26. }
  27.  
  28. int strcmp(char *text, char *pattern)
  29. {
  30.     int x = strlen(text), y = strlen(pattern), n = (x < y? x: y), i;
  31.     for(i = 0; i < n; i++)
  32.     {
  33.         if(*(text + i) < *(pattern + i)) {
  34.             return -1;
  35.         }
  36.         else if(*(text + i) > *(pattern + i)) {
  37.             return 1;
  38.         }
  39.     }
  40.     if(x == y) {
  41.         return 0;
  42.     }
  43.     else if(x < y) {
  44.         return -1;
  45.     }
  46.     else {
  47.         return 1;
  48.     }
  49. }
  50.  
  51. int main()
  52. {
  53.     char a[256];
  54.     char b[256];
  55.  
  56.     gets(a); gets(b);
  57.  
  58.     printf("%d\n", strcmp(a, b));
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement