SHARE
TWEET

Untitled

a guest Jul 21st, 2019 100 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. void balanced(char balance[]);
  6.  
  7. int main()
  8. {
  9.  
  10. //balanced("xxxyyy");
  11. //balanced("yyyxxx");
  12. balanced("xxxyyyy");
  13. //balanced("yyxyxxyxxyyyyxxxyxyx");
  14. //balanced("xyxxxxyyyxyxxyxxyy");
  15. //balanced("");
  16. //balanced("x") ;
  17.  
  18.  
  19.     return 0;
  20. }
  21.  
  22.  
  23. void balanced(char balance[]){
  24.  
  25.     int x = 0;
  26.     int y = 0;
  27.  
  28.  
  29.     for(int i=0; i<strlen(balance); i++){
  30.         if(balance[i] == "x"){
  31.             x++;
  32.         }
  33.         else if (balance[i] == "y"){
  34.             y++;
  35.         }
  36.     }
  37.  
  38.  
  39.  
  40.     if(x==y){
  41.         printf("true\n");
  42.     }
  43.     else{
  44.         printf("false\n");
  45.     }
  46.  
  47.     return;
  48. }
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