Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <iostream.h>
  3. #include <math.h>
  4. #include <stdio.h>
  5. #include <time.h>
  6. // -Structuri
  7. struct nod
  8. {
  9. int val;
  10. nod *next;
  11. };
  12.  
  13. struct coada
  14. {
  15. nod *vf, *sf;
  16. int vid;
  17. };
  18.  
  19. // -Definiri
  20. void init(coada);
  21. void deal();
  22. void add(coada & , int);
  23. void extract(coada, int &);
  24. void afis_before(coada, coada);
  25. void afis_after(coada);
  26.  
  27. coada p1,p2;
  28.  
  29. int main()
  30. {
  31. init(p1);
  32. init(p2);
  33. deal();
  34. afis_before(p1,p2);
  35.  
  36. return 0;
  37. }
  38.  
  39. void init(coada c)
  40. {
  41. c.vf=NULL;
  42. c.sf=NULL;
  43. c.vf->next=NULL;
  44. c.sf->next=NULL;
  45. }
  46.  
  47. void deal()
  48. {
  49. int i=1,v[15],card;
  50. for(i=1;i<=14;i++)
  51. v[i]=4;
  52. //Jucator 1
  53. randomize();
  54. for(i=1;i<=26;i++)
  55. {
  56.  
  57. xx: card=rand()%13+2;
  58. if(!v[card]) goto xx;
  59. else
  60. {
  61. v[card]--;
  62. add(p1,card);
  63. }
  64. }
  65. //Jucator 2
  66. randomize();
  67. for(i=1;i<=26;i++)
  68. {
  69.  
  70. yy: card=rand()%13+2;
  71. if(!v[card]) goto yy;
  72. else
  73. {
  74. v[card]--;
  75. add(p2,card);
  76. }
  77. }
  78. }
  79. void add(coada &c, int x)
  80. {
  81. nod *n=new(nod);
  82. n->val=x;
  83. n->next=NULL;
  84. if(!c.vf) c.vf=n;
  85. else c.sf->next=n;
  86. c.sf=n;
  87. }
  88.  
  89. void extract(coada c, int &x)
  90. {
  91. nod *n;
  92. n=c.vf;
  93. x=c.vf->val;
  94. if(c.vf==c.sf) c.vid=0;
  95. else
  96. c.vf=c.vf->next;
  97. delete(n);
  98. }
  99.  
  100. void afis_before(coada c1, coada c2)
  101. {
  102. nod *n;
  103. n=c1.vf;
  104. cout<<"Player 1: ";
  105. while(n)
  106. {
  107. if(n->val!=11) cout<<n->val<<" ";
  108. else cout<<"A ";
  109. n=n->next;
  110. }
  111. cout<<endl;
  112.  
  113. n=c2.vf;
  114. cout<<"Player 2: ";
  115. while(n)
  116. {
  117. if(n->val!=11) cout<<n->val<<" ";
  118. else cout<<"A ";
  119. n=n->next;
  120. }
  121. cout<<endl;
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement