Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wu-e002
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Pedro Rolon
wu-e002
Commits
862bcb6c
You need to sign in or sign up before continuing.
Commit
862bcb6c
authored
Oct 08, 2018
by
Pedro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
"Se agregó el archivo de juego toros y vacas!"
parents
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
164 additions
and
0 deletions
+164
-0
a.out
+0
-0
torosvacas.cpp
+164
-0
No files found.
a.out
0 → 100755
View file @
862bcb6c
File added
torosvacas.cpp
0 → 100644
View file @
862bcb6c
#include <bits/stdc++.h>
#define N 4
#define INTENTOS 12
void
separar_numeros
(
int
vector
[
N
],
int
numero
);
int
aleatorio
(
int
x
,
int
y
);
bool
tiene_cuatro_digitos
(
int
n
);
using
namespace
std
;
int
main
(){
srand
(
time
(
NULL
));
int
numero_pensado
[
N
];
int
numero_input
[
N
];
int
input
;
bool
error
=
false
;
for
(
int
i
=
0
;
i
<
N
;
i
++
){
int
temp
=
aleatorio
(
1
,
9
);
for
(
int
j
=
0
;
j
<
(
i
+
1
);
j
++
){
if
(
numero_pensado
[
j
]
==
temp
){
temp
=
aleatorio
(
1
,
9
);
j
=
0
;
}
}
numero_pensado
[
i
]
=
temp
;
}
for
(
int
i
=
0
;
i
<
N
;
i
++
){
cout
<<
numero_pensado
[
i
];
}
cout
<<
endl
;
cout
<<
"Ya pensé en número!"
<<
endl
;
int
toros
=
0
;
int
vacas
=
0
;
for
(
int
i
=
0
;
i
<
INTENTOS
;
i
++
)
{
do
{
cout
<<
"INTENTO B 0"
<<
i
+
1
<<
" : "
;
toros
=
0
;
vacas
=
0
;
cin
>>
input
;
if
(
!
tiene_cuatro_digitos
(
input
)){
cout
<<
"Jugada Inválida - Número Inválido
\n
"
;
error
=
true
;
//i--;
continue
;
}
else
{
error
=
false
;
separar_numeros
(
numero_input
,
input
);
for
(
int
j
=
0
;
j
<
N
;
j
++
)
{
for
(
int
k
=
j
+
1
;
k
<
N
;
k
++
){
if
(
numero_input
[
j
]
==
numero_input
[
k
]){
cout
<<
"Jugada Inválida - Número con dígitos repetidos"
<<
endl
;
error
=
true
;
j
=
N
;
}
}
}
}
}
while
(
error
);
int
iguales
=
0
;
for
(
int
j
=
0
;
j
<
4
;
j
++
)
{
if
(
numero_pensado
[
j
]
==
numero_input
[
j
]){
iguales
++
;
}
}
if
(
iguales
==
4
){
cout
<<
"FIN DEL JUEGO - GANÓ B en "
;
cout
<<
i
+
1
<<
" INTENTOS"
<<
endl
;
return
0
;
}
for
(
int
i
=
0
;
i
<
4
;
i
++
)
{
for
(
int
j
=
0
;
j
<
4
;
j
++
)
{
if
(
numero_pensado
[
i
]
==
numero_input
[
j
]){
if
(
i
==
j
){
toros
++
;
}
else
{
vacas
++
;
}
}
}
}
cout
<<
"RESPUESTA A: "
;
cout
<<
toros
<<
" TOROS, "
;
cout
<<
vacas
<<
" VACAS"
<<
endl
;
}
cout
<<
"SUPERASTE LOS "
<<
INTENTOS
<<
" INTENTOS"
<<
endl
;
cout
<<
"PERDISTE B)"
<<
endl
;
return
0
;
}
//función para generar numeros aleatorios
int
aleatorio
(
int
x
,
int
y
){
return
int
(
x
+
rand
()
%
(
y
+
1
-
x
));
}
//función para separar los digitos en un vector
void
separar_numeros
(
int
vector
[
N
],
int
numero
){
int
dividendo
=
1000
;
for
(
int
i
=
0
;
i
<
N
;
i
++
){
int
x
=
numero
/
dividendo
;
vector
[
i
]
=
x
;
numero
=
numero
-
(
x
*
dividendo
);
dividendo
=
dividendo
/
10
;
}
}
bool
tiene_cuatro_digitos
(
int
n
){
if
(
int
(
n
/
1000
)
!=
0
and
int
(
n
/
10000
)
==
0
){
return
true
;
}
return
false
;
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment