Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement