Yam Code
Sign up
Login
New paste
Home
Trending
Archive
English
English
Tiếng Việt
भारत
Sign up
Login
New Paste
Browse
#include <iostream> #include <ctime> #include <cstdlib> #define CARD 52 #define SUITS 4 #define RANKS 13 using namespace std; void print(int deck[SUITS][RANKS]) { for (int i = 0; i < SUITS; i++) { for (int j = 0; j < RANKS; j++) { cout << deck[i][j] << "\t"; } cout << endl; } } int convertToPoint(const char ch[]) { if (ch == "Ace") return 1; if (ch == "Two") return 2; if (ch == "Three") return 3; if (ch == "Four") return 4; if (ch == "Five") return 5; if (ch == "Six") return 6; if (ch == "Seven") return 7; if (ch == "Eight") return 8; if (ch == "Nine") return 9; if (ch == "Ten") return 10; if (ch == "Jack") return 11; if (ch == "Queen") return 12; if (ch == "King") return 13; return 0; } void shuffleCards(int deck[][RANKS]){ srand(time(0)); for (int card = 1; card <= CARD; card++) { int row; int col; do { row = rand() % SUITS; col = rand() % RANKS; } while (deck[row][col] != NULL); deck[row][col] = card; } } void printCardsShuffling(int deck[][RANKS], const char* suits[], const char* ranks[]) { for (int card = 1; card <= CARD; card++) { for (int i = 0; i < SUITS; i++) { for (int j = 0; j < RANKS; j++) { if (deck[i][j] == card) { cout << "(" << suits[i] << "," << ranks[j] << ")" << endl; } } } } } int** dealingForHand(int deck[SUITS][RANKS]) { int** result = new int*[5]; for (int i = 0; i < 5; i++) { result[i] = new int[3]; } for (int card = 1; card <= 5; card++) { int row = card - 1; for (int i = 0; i < SUITS; i++) { for (int j = 0; j < RANKS; j++) { if (deck[i][j] == card) { // The 1 co dia chi i va j result[row][0] = i; result[row][1] = j; result[row][2] = 0; } } } } return result; } void printHand(int** hand, const char* suits[], const char* ranks[]) { for (int i = 0; i < 5; i++) hand[i][2] = convertToPoint(ranks[hand[i][1]]); cout << endl; for (int i = 0; i < 5; i++) { cout << "(" << suits[hand[i][0]] << "," << ranks[hand[i][1]] << ")" << endl; } } int isFourOfAKind(int** hand) { for (int i = 0; i < 5; i++) { int temp = 0; for (int j = 0; j < 5; j++) { if (hand[i][2] == hand[j][2]) { temp++; cout << temp << endl; } if (temp == 4) return 1; } } return 0; } int main() { int deck[SUITS][RANKS] = { 0 }; shuffleCards(deck); print(deck); cout << endl; const char* suits[SUITS] = { "Hearts", "Diamonds", "Clubs", "Spades" }; const char* ranks[RANKS] = { "Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King" }; printCardsShuffling(deck, suits, ranks); int** hand = dealingForHand(deck); printHand(hand, suits, ranks); // The number of card of one player is 5 => 5 rows // Column J is column writing the position and value (value cof card in random 52 cards.) for (int i = 0; i < 5; i++) { for (int j = 0; j < 3; j++) { cout << hand[i][j] << "\t"; } cout << endl; } //Check Four of a kind if (isFourOfAKind(hand) == 1) cout << "Four of a kind"; else cout << "Not four of a kind"; return 0; }
Paste Settings
Paste Title :
[Optional]
Paste Folder :
[Optional]
Select
Syntax Highlighting :
[Optional]
Select
Markup
CSS
JavaScript
Bash
C
C#
C++
Java
JSON
Lua
Plaintext
C-like
ABAP
ActionScript
Ada
Apache Configuration
APL
AppleScript
Arduino
ARFF
AsciiDoc
6502 Assembly
ASP.NET (C#)
AutoHotKey
AutoIt
Basic
Batch
Bison
Brainfuck
Bro
CoffeeScript
Clojure
Crystal
Content-Security-Policy
CSS Extras
D
Dart
Diff
Django/Jinja2
Docker
Eiffel
Elixir
Elm
ERB
Erlang
F#
Flow
Fortran
GEDCOM
Gherkin
Git
GLSL
GameMaker Language
Go
GraphQL
Groovy
Haml
Handlebars
Haskell
Haxe
HTTP
HTTP Public-Key-Pins
HTTP Strict-Transport-Security
IchigoJam
Icon
Inform 7
INI
IO
J
Jolie
Julia
Keyman
Kotlin
LaTeX
Less
Liquid
Lisp
LiveScript
LOLCODE
Makefile
Markdown
Markup templating
MATLAB
MEL
Mizar
Monkey
N4JS
NASM
nginx
Nim
Nix
NSIS
Objective-C
OCaml
OpenCL
Oz
PARI/GP
Parser
Pascal
Perl
PHP
PHP Extras
PL/SQL
PowerShell
Processing
Prolog
.properties
Protocol Buffers
Pug
Puppet
Pure
Python
Q (kdb+ database)
Qore
R
React JSX
React TSX
Ren'py
Reason
reST (reStructuredText)
Rip
Roboconf
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Soy (Closure Template)
Stylus
Swift
TAP
Tcl
Textile
Template Toolkit 2
Twig
TypeScript
VB.Net
Velocity
Verilog
VHDL
vim
Visual Basic
WebAssembly
Wiki markup
Xeora
Xojo (REALbasic)
XQuery
YAML
HTML
Paste Expiration :
[Optional]
Never
Self Destroy
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Status :
[Optional]
Public
Unlisted
Private (members only)
Password :
[Optional]
Description:
[Optional]
Tags:
[Optional]
Encrypt Paste
(
?
)
Create New Paste
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Site Languages
×
English
Tiếng Việt
भारत