Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Devon Puchailo (drp882)
SampleAssignment
Commits
badb0c8c
Commit
badb0c8c
authored
Sep 11, 2017
by
Chris Dutchyn (cjd032)
Browse files
Input complete.
parent
31305e30
Changes
6
Hide whitespace changes
Inline
Side-by-side
Makefile
View file @
badb0c8c
# Makefile for Sample Assignment
# compiler settings
CC
=
c++
CXXFLAGS
=
-Wall
-pedantic
-ansi
# binaries
BIN
=
pm
SRCS
=
$(BIN)
.cc
OBJS
=
$(BIN)
.o
# the default target
all
:
$(BIN)
pm.o
:
pm.cc pm.h
io.o
:
io.cc pm.h
gs.o
:
gs.cc pm.h
pm
:
pm.o io.o gs.o
# tests
tests
:
test0.out test1.out test2A.out test2B.out
...
...
@@ -18,8 +26,8 @@ tests: test0.out test1.out test2A.out test2B.out
SED
=
/usr/bin/sed
DIFF
=
/usr/bin/diff
%.out
:
$(BIN) %.in %.exp
$(SED)
-e
's/[ ]*#
#
.*$$//'
<
$*
.in
>
$*
.in~ 2>/dev/tty
$(SED)
-e
's/[ ]*#
#
.*$$//'
<
$*
.exp
>
$*
.out~ 2>/dev/tty
$(SED)
-e
's/[ ]*#.*$$//'
<
$*
.in
>
$*
.in~ 2>/dev/tty
$(SED)
-e
's/[ ]*#.*$$//'
<
$*
.exp
>
$*
.out~ 2>/dev/tty
./
$(BIN)
<
$*
.in~
>
$*
.out 2>/dev/tty
$(DIFF)
-q
$*
.out
$*
.out~
...
...
README.md
View file @
badb0c8c
...
...
@@ -56,3 +56,6 @@ available to indicate free for both companies and interns.
We have a
`Makefile`
and targets
*
`all`
to build the binary (
`pm`
)
*
`tests`
to run all the tests (so far,
`test0`
,
`test1`
,
`test2A`
,
`test2B`
)
We can try individual tests by
`make test1.out`
. Also, the C/C++ standard
macro DEBUG can be defined to enable some debugging output.
gs.cc
0 → 100644
View file @
badb0c8c
#include
"pm.h"
void
gale_shapley
()
{
}
io.cc
0 → 100644
View file @
badb0c8c
#define DEBUG
#include
<iostream>
#include
<cassert>
#include
<cstdlib>
#include
"pm.h"
static
bool
valid_company
(
const
company
&
c
)
{
bool
*
interns
=
new
bool
[
N
+
1
];
for
(
int
i
=
0
;
i
<=
N
;
i
+=
1
)
{
interns
[
i
]
=
false
;
}
for
(
int
o
=
0
;
o
<
N
;
o
+=
1
)
{
int
k
=
c
.
interns
.
options
[
o
];
assert
(
!
interns
[
k
]);
interns
[
k
]
=
true
;
}
return
true
;
}
static
void
write_company
(
const
company
&
c
)
{
#ifdef DEBUG
cerr
<<
c
.
name
<<
" :"
;
for
(
int
o
=
0
;
o
<
N
;
o
+=
1
)
{
cerr
<<
" "
<<
c
.
interns
.
options
[
o
];
}
cerr
<<
" ... "
<<
c
.
intern
;
cerr
<<
endl
;
#endif //DEBUG
}
static
void
read_company
(
company
&
c
)
{
cin
>>
c
.
name
;
c
.
interns
.
options
=
new
int
[
N
];
for
(
int
o
=
0
;
o
<
N
;
o
+=
1
)
{
int
i
;
cin
>>
i
;
assert
(
i
>
0
&&
i
<=
N
);
c
.
interns
.
options
[
o
]
=
i
;
}
c
.
interns
.
next_option
=
0
;
c
.
intern
=
FREE
;
cin
.
ignore
();
write_company
(
c
);
assert
(
valid_company
(
c
));
}
static
bool
valid_intern
(
const
intern
&
i
)
{
bool
*
companies
=
new
bool
[
N
+
1
];
for
(
int
c
=
0
;
c
<=
N
;
c
+=
1
)
{
companies
[
c
]
=
false
;
}
for
(
int
o
=
0
;
o
<
N
;
o
+=
1
)
{
int
k
=
i
.
companies
.
options
[
o
];
assert
(
!
companies
[
k
]);
companies
[
k
]
=
true
;
}
return
true
;
}
static
void
write_intern
(
const
intern
&
i
)
{
#ifdef DEBUG
cerr
<<
i
.
name
<<
" :"
;
for
(
int
o
=
0
;
o
<
N
;
o
+=
1
)
{
cerr
<<
" "
<<
i
.
companies
.
options
[
o
];
}
cerr
<<
" ... "
<<
i
.
company
;
cerr
<<
endl
;
#endif //DEBUG
}
static
void
read_intern
(
intern
&
i
)
{
cin
>>
i
.
name
;
i
.
companies
.
options
=
new
int
[
N
];
for
(
int
o
=
0
;
o
<
N
;
o
+=
1
)
{
int
c
;
cin
>>
c
;
assert
(
c
>
0
&&
c
<=
N
);
i
.
companies
.
options
[
o
]
=
c
;
}
i
.
companies
.
next_option
=
0
;
i
.
company
=
FREE
;
cin
.
ignore
();
write_intern
(
i
);
assert
(
valid_intern
(
i
));
}
void
read_input
()
{
cin
>>
N
;
cin
.
ignore
();
#ifdef DEBUG
cerr
<<
"Expecting "
<<
N
<<
" companies and interns."
<<
endl
;
#endif //DEBUG
companies
=
new
company
[
N
+
1
];
companies
[
0
].
name
=
"INVALID COMPANY"
;
// !NB! impossible company name
companies
[
0
].
interns
.
options
=
NULL
;
companies
[
0
].
interns
.
next_option
=
0
;
companies
[
0
].
intern
=
FREE
;
for
(
int
i
=
1
;
i
<=
N
;
i
+=
1
)
{
read_company
(
companies
[
i
]);
}
interns
=
new
intern
[
N
+
1
];
interns
[
0
].
name
=
"INVALID INTERN"
;
// !NB! impossible intern name
interns
[
0
].
companies
.
options
=
NULL
;
interns
[
0
].
companies
.
next_option
=
0
;
interns
[
0
].
company
=
FREE
;
for
(
int
i
=
1
;
i
<=
N
;
i
+=
1
)
{
read_intern
(
interns
[
i
]);
}
#ifdef DEBUG
for
(
int
c
=
1
;
c
<=
N
;
c
+=
1
)
{
cerr
<<
"Company "
<<
companies
[
c
].
name
<<
" wants"
;
for
(
int
o
=
0
;
o
<
N
;
o
+=
1
)
{
cerr
<<
" "
<<
interns
[
companies
[
c
].
interns
.
options
[
o
]].
name
<<
"("
<<
companies
[
c
].
interns
.
options
[
o
]
<<
") "
;
}
cerr
<<
endl
;
}
for
(
int
i
=
1
;
i
<=
N
;
i
+=
1
)
{
cerr
<<
"Intern "
<<
interns
[
i
].
name
<<
" wants"
;
for
(
int
o
=
0
;
o
<
N
;
o
+=
1
)
{
cerr
<<
" "
<<
companies
[
interns
[
i
].
companies
.
options
[
o
]].
name
<<
"("
<<
interns
[
i
].
companies
.
options
[
o
]
<<
") "
;
}
cerr
<<
endl
;
}
#endif //DEBUG
}
void
write_output
()
{
}
pm.cc
View file @
badb0c8c
#include
<iostream>
#include
<cassert>
#include
<cstdlib>
using
namespace
std
;
#include
"pm.h"
int
N
=
0
;
company
*
companies
=
NULL
;
intern
*
interns
=
NULL
;
int
main
(
void
)
{
read_input
();
gale_shapley
();
write_output
();
return
EXIT_SUCCESS
;
}
pm.h
0 → 100644
View file @
badb0c8c
#include
<string>
using
namespace
std
;
const
int
FREE
=
0
;
typedef
struct
ordered_list
{
int
*
options
;
int
next_option
;
}
ordered_list
;
typedef
struct
company
{
string
name
;
ordered_list
interns
;
int
intern
;
}
company
;
typedef
struct
intern
{
string
name
;
ordered_list
companies
;
int
company
;
}
intern
;
extern
company
*
companies
;
extern
intern
*
interns
;
extern
int
N
;
void
read_input
();
void
gale_shapley
();
void
write_output
();
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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