SHARE
TWEET

Untitled

a guest Dec 14th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int compare(const void* a, const void* b)
  2. {
  3.      const char* str1 = *(char**)a;
  4.      const char* str2 = *(char**)b;
  5.    
  6.      bool isStr1HasDigit = false;
  7.      bool isStr2HasDigit = false;
  8.  
  9.      int sum1 = 0;
  10.      int sum2 = 0;
  11.    
  12.      for (int i = 0; str1[i]; i++)
  13.     if(isdigit(str1[i])){
  14.         sum1+=str1[i]-'0';
  15.         isStr1HasDigit = true;
  16.     }
  17.     for (int i = 0; str2[i]; i++)
  18.     if(isdigit(str2[i])){
  19.         sum2+=str2[i]-'0';
  20.         isStr2HasDigit = true;
  21.     }
  22.     if(!isStr1HasDigit)
  23.         return -1;
  24.     if(!isStr2HasDigit)
  25.         return 1;
  26.     return sum1-sum2;
  27. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top