Advertisement
JohnathanMayhem

Rita

Feb 21st, 2022
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.61 KB | None | 0 0
  1. #include <string.h>
  2. #include <stdio.h>
  3.  
  4. //gets(), strtok(), sscanf()
  5. int compare(float *list1, float *list2){
  6.     for (int i = 0; i < 3; ++i) {
  7.         if (list1[i]>list2[i]){
  8.             return 1;
  9.         }else{
  10.             if (list1[i]<list2[i]){
  11.                 return -1;
  12.             }else{
  13.                 continue;
  14.             }
  15.         }
  16.     }
  17.     return 0;
  18. }
  19. void read(float *o, float *list){
  20.     char *opened, temp[50] = {"0"};
  21.     opened = strtok(list ," ");
  22.     while (opened != NULL){
  23.         if(opened[0]>47 && opened[0]<58){
  24.             sscanf(opened, "%f", &o[0]);
  25.         } else if(opened[0]=='N'){
  26.             if(strlen(opened)==1){
  27.                 o[1]=1;
  28.             } else {
  29.                 strcpy(temp, &opened[2]);
  30.                 sscanf(temp, "%f", &o[1]);
  31.             }
  32.         } else if(opened[0]=='l'){
  33.             if(strlen(opened)==4){
  34.                 o[2]=1;
  35.             } else {
  36.                 strcpy(temp, &opened[5]);
  37.                 float te;
  38.                 sscanf(temp, "%f", &te);
  39.                 o[2]=te;
  40.             }
  41.         }
  42.         opened = strtok(NULL, " ");
  43.     }
  44. }
  45. int main(){
  46.     int q, q1;
  47.     scanf("%d", &q);
  48.     char rubbish;
  49.     char list1[50] = "0";
  50.     char list2[50] = "0";
  51.     char *opened1, *opened2;
  52.     scanf("%c", &rubbish);
  53.     q1 = q;
  54.     for (int i = 0; i<q1; ++i){
  55.         gets(list1);
  56.         gets(list2);
  57.         float o1[3] = {1, 0, 0};
  58.         float o2[3]= {1, 0, 0};
  59.         read(o1, list1);
  60.         read(o2, list2);
  61.         int res = compare(o1, o2);
  62.         printf("%d\n", compare(o1, o2));
  63.     }
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement