fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int const SEED = 31415926;
  5. int main() {
  6. int c;
  7. int count0, count1;
  8. srand(SEED);
  9. count0 = count1 = 0;
  10. while ((c = fgetc(stdin)) != EOF) {
  11. if (c == '0')
  12. count0++;
  13. else if (c == '1')
  14. count1++;
  15. }
  16. while (count0 > 0 || count1 > 0) {
  17. int f;
  18. f = (int)((double)rand() / ((double)RAND_MAX + 1) * (count0 + count1));
  19. if (f >= count0) {
  20. fputc('1', stdout);
  21. count1--;
  22. } else {
  23. fputc('0', stdout);
  24. count0--;
  25. }
  26. }
  27. return 0;
  28. }
  29. /* end */
  30.  
Success #stdin #stdout 0s 1788KB
stdin
Standard input is empty
stdout
Standard output is empty