josiftepe

Untitled

Dec 31st, 2020
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.23 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<ctype.h>
  3. #include<string.h>
  4. #define MAX 50
  5.  
  6. char* revertString(char *a, char *b, char *comparator){
  7.  
  8.     a[strlen(a)-1] = '\0';
  9.     b[strlen(b)-1] = '\0';
  10.     comparator[strlen(comparator)-1] = '\0';
  11.     for(int i=0; i<strlen(comparator); i++){
  12.         comparator[i] = tolower(comparator [i]);
  13.     }
  14.  
  15.     int n = strlen(a);
  16.     for(int i=0; i<n/2; i++){
  17.         char temp = a[i];
  18.         a[i] = a[n-i-1];
  19.         a[n-i-1] = temp;
  20.     }
  21.  
  22.     n = strlen(b);
  23.     for(int i=0; i<n/2; i++){
  24.         char temp = b[i];
  25.         b[i] = b[n-i-1];
  26.         b[n-i-1] = temp;
  27.     }
  28.     if(strcmp(comparator, "pogolem") == 0){
  29.             if(strcmp(a,b) > 0)
  30.             return a;
  31.                   else return b;
  32.     }
  33.     else if(strcmp(comparator, "pomal") == 0){
  34.         if(strcmp(a,b) < 0)
  35.         return a;
  36.               else return b;
  37. }
  38. else return "Invalid comparator";
  39. }
  40.  
  41. int main(){
  42.     char a[MAX], b[MAX], comparator[MAX];
  43.     int n;
  44.     scanf("%d\n", &n);
  45.     for(int i=0; i<n; i++){
  46.             fgets(a, sizeof(a),stdin);
  47.         fgets(b, sizeof(b),stdin);
  48.         fgets(comparator, sizeof(comparator),stdin);
  49.         printf("%s\n", revertString(a,b,comparator));
  50.     }
  51.     return 0;
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment