fork download
  1. // BINGO lottery machine
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <time.h>
  7.  
  8. // (int reset) = 0:draw number, 1:reset number
  9. int bingo_draw_number(int reset) {
  10. static int s[75] = {0};
  11. static int pos = 0;
  12. int a1, a2, tmp, i, bn;
  13.  
  14. if (reset) {
  15. // [1..75] into array
  16. for (i = 0; i < 75; i++) {
  17. s[i] = i + 1;
  18. }
  19. // random swap 1000 times
  20. srand(time(NULL));
  21. for (i = 0; i < 1000; i++) {
  22. a1 = rand() % 75;
  23. a2 = rand() % 75;
  24. tmp = s[a1];
  25. s[a1] = s[a2];
  26. s[a2] = tmp;
  27. }
  28. // reset cursor position
  29. pos = 0;
  30. return 0;
  31. }
  32.  
  33. // draw number
  34. if (pos < 75) {
  35. bn = s[pos];
  36. pos++;
  37. } else {
  38. bn = 0;
  39. }
  40.  
  41. return bn;
  42. }
  43.  
  44. int main(void) {
  45. // your code goes here
  46. char *tc[5] = {"B", "I", "N", "G", "O"};
  47. int bn, i;
  48.  
  49. bingo_draw_number(1);
  50. printf("%s\n", "Draw start.");
  51. for (i = 1; i <= 75; i++) {
  52. bn = bingo_draw_number(0);
  53. if (bn) {
  54. printf("[%2d] ---> %s %d\n", i, tc[(bn-1)/15], bn);
  55. }
  56. }
  57. return 0;
  58. }
  59.  
Success #stdin #stdout 0s 4464KB
stdin
Standard input is empty
stdout
Draw start.
[ 1] ---> B 6
[ 2] ---> I 28
[ 3] ---> I 22
[ 4] ---> B 2
[ 5] ---> G 46
[ 6] ---> B 9
[ 7] ---> B 12
[ 8] ---> I 29
[ 9] ---> B 11
[10] ---> N 34
[11] ---> G 49
[12] ---> I 21
[13] ---> G 48
[14] ---> G 55
[15] ---> G 60
[16] ---> G 56
[17] ---> G 52
[18] ---> N 32
[19] ---> N 37
[20] ---> B 14
[21] ---> G 57
[22] ---> N 42
[23] ---> O 74
[24] ---> G 51
[25] ---> N 36
[26] ---> O 65
[27] ---> I 20
[28] ---> O 63
[29] ---> I 19
[30] ---> G 53
[31] ---> I 30
[32] ---> I 17
[33] ---> O 64
[34] ---> B 5
[35] ---> O 75
[36] ---> O 67
[37] ---> O 70
[38] ---> O 61
[39] ---> N 40
[40] ---> B 7
[41] ---> O 69
[42] ---> G 47
[43] ---> I 18
[44] ---> N 43
[45] ---> O 62
[46] ---> I 27
[47] ---> N 38
[48] ---> O 72
[49] ---> I 25
[50] ---> N 41
[51] ---> N 44
[52] ---> N 39
[53] ---> N 31
[54] ---> I 26
[55] ---> B 8
[56] ---> G 50
[57] ---> B 15
[58] ---> B 4
[59] ---> B 10
[60] ---> O 66
[61] ---> N 35
[62] ---> O 68
[63] ---> O 71
[64] ---> N 45
[65] ---> I 24
[66] ---> G 54
[67] ---> G 58
[68] ---> G 59
[69] ---> I 16
[70] ---> B 3
[71] ---> O 73
[72] ---> N 33
[73] ---> I 23
[74] ---> B 13
[75] ---> B 1