Title: CS 60 Slides
1Welcome to Programming Practicum
Putting the C into CS
University of St. Petersburg
Waiting for the snow enveloping you on Route 5 N
to melt
Engineering dept.
On the 405, in traffic, being chased by police
(and TV) helicopters.
You arent here
writing clinic reports
Lecture
rebooting turing
coding chunky strings
reading requests
clinic liaison phone call
Mailing something at the Claremont Post Office
the dumpster
2What is this course about?
- A chance to improve your C/C
3What is this course about?
- A chance to improve your C/C
Unofficial course name CS -70
4What is this course about?
- A chance to improve your C/C
Unofficial course name CS -70
Code commenting Using globals Building
classes STL Memory Leaks
5What is this course about?
- A chance to improve your C/C
Unofficial course name CS -70
CS 70
Code commenting Using globals Building
classes STL Memory Leaks
6What is this course about?
- A chance to improve your C/C
Unofficial course name CS -70
CS 70
Code commenting Using globals Building
classes STL Memory Leaks
- Problem Insight and Execution ...
- Preparation for the ACM competition ...
72000 ACM Teams
8Organization
a must!
Solving problems in teams
- 3 team members, more or less
- 2 problems/week, more or less
- submission through /cs/ACM/acmSubmit
- class web page at www.cs.hmc.edu/ACM
9Grading
P/F by default -- but it can be graded
- 1.75 problems/week gt A
- 1.25 problems/week gt B
- 0.75 problems/week gt C
- 0.25 problems/week gt D
Coding Guidelines
- share coding tasks within teams, not among them
- discussion of algorithms always OK
- start from scratch each time!
10Course Outline
Sep 11 continental fare Sep 18 slim
jims Sep 25 Pepperedge Farm Oct 2
Krispy Kreme Oct 9 Drakes coffee cake Oct
16 baklava Oct 23 (fall break) Oct 30
HMC Contest - 900 pm to 100 am ? Nov 6
popcorn Nov 10 (Sat) -- ACM Contest at
Riverside Com. Col. Nov 13 Wrap-up and
problem discussion
11ACM topics
Contest
CS
Topic
Standard Library (STL)
Algorithms/data structures
Overlearning the above
Coding/Contest strategies
12ACM topics
Contest
CS
Topic
Standard Library (STL)
Algorithms/data structures
Overlearning the above
Coding/Contest strategies
13ACM topics
Contest
CS
Topic
Standard Library (STL)
Algorithms/data structures
Overlearning the above
Coding/Contest strategies
14ACM topics
Contest
CS
Topic
Standard Library (STL)
Algorithms/data structures
Overlearning the above
Coding/Contest strategies
15Problems
The digital root problem. (digroot.cc)
starting...
The unscramble problem. (unscramble.cc)
sorting...
The echo problem. (echo.cc)
Input
Intergalactic IRC strings
stdin
hehelllloo spamanyspamone howstheweather
16Problems
The digital root problem. (digroot.cc)
starting...
The unscramble problem. (unscramble.cc)
sorting...
The echo problem. (echo.cc)
Input
Intergalactic IRC strings
stdin
An echo string with buffer size ten
hehelllloo spamanyspamone howstheweather
Not an echo string, but still consistent
Not consistent with the theory
Output
Status Report
stdout
17Resources...
http//www.sgi.com/tech/stl/
Both good overall references
Online STL refs
http//www.dinkumware.com/htm_cpl/index.html
http//www.josuttis.com/libbook/
Example code
Useful stuff for this weeks problems
string t, s Hawaii 2002 getline(cin,t) //
suppose t is Harvey Mudd if (t gt s) //
comparison (, !, ) t i n s
// concatenation s t.substr(7,4) // s
is Mudd s1 // s1 is
u s.length() // returns 4 t.find(a)
// returns 1 (where a is) t.find(a,2) //
returns 16 (starts at 2) // find returns a value
of type stringsize_type // if what is sought
isnt there, find returns stringnpos
string
include ltstringgt
18Resources...
typedef pairltstring, stringgt PS PS mypair
make_pair(hello,world) mypair.first //
these are public members mypair.second struct
MYLESS public lesslt PS gt bool operator()(PS
x,PS y) return x.second lt y.second //
etc. MYLESS mybad PS psArray new
PS1000 // array of PS // putting mybad to
work... sort( psArray, psArrayn ) // default
sort sort( psArray, psArrayn, mybad )
pair
include ltutilitygt
function objects
less
include ltfunctionalgt
sort
include ltalgorithmgt
19(No Transcript)
20Resources...
typedef pairltstring, stringgt PSS PSS mypair
make_pair(hello,world) mypair.first //
these are public members mypair.second vectorltPS
Sgt v // typedefs good v.reserve(10)
// assure 10 spots v.push_back(mypair) //
mypair -gt last item v.back() //
returns mypair v.pop_back() // removes
last element v.size() // of
elements vi // ith
element sort( v.begin(), v.end() ) // default
sort sort( v.begin(), v.end(), mycompare )
pair
include ltutilitygt
vector
include ltvectorgt
sort
include ltalgorithmgt
21Intro STL Data Structure
The split pea problem (also see the webpage)
The number of configurations the of cups to
follow the of peas in each cup of
cups of peas ...
2 5 1 3 0 3 0 3 7 0 7
Input
stdin
input
3 2
The of transitions from a root configuration to
the given one.
Output
stdout
output
shaken or stirred?
22Intro Problem
The NAND problem (also see the webpage)
file to create nand.cc
NAND
Problem
x y xy 0 0 1 0 1 1 1 0 1 1 1 0
NAND gates can specify any logical
function. Consider two N-bit binary numbers, A
and B. There is a logical function mapping A and
B to the overflow bit of their sum.
A 10
B 11
AB 101
the overflow bit -- its a function of the input
bits
23Intro Problem
The NAND problem (also see the webpage)
file to create nand.cc
Problem
NAND gates can specify any logical
function. Consider two N-bit binary numbers, A
and B. There is a logical function mapping A and
B to the overflow bit of their sum.
1 10 10 20
Lines with two integers gt 0.
Input
Same lines, plus the max of steps to get to 1
in the given range.
1 10 20 10 20 21
Output
24Topics Outline
Sep 5 Basic coding strategies (ACM
style) Sep 12 Dynamic programming n data
structures Sep 19 Search algorithms n data
structures Sep 26 Numerical algorithms DEs,
equations Oct 3 I/O in C/C building
parsers quickly Oct 10 Built-in string
functions strcmp, strtok, and the like Oct 24
Built-in math functions atan vs. atan2,
precision issues, ... Oct 31 Geometric
algorithms n data structures Nov 7 Contest
strategies, logistics, preparing materials
25What is this course about?
A chance to improve your C/C
prog practice
Preparation for the ACM competition ...
Problem Insight and Execution ...
2
1
Anxiety!
Get into the minds of the judges
26Key Skill 1 mindreading
27Key Skill 2 anxiety
Anxiety!
28What, no contest!?
We will have a mock contest at the end of the
term.
- tentatively Tuesday, April 17
- four hours (from 415 to 815)
- contest conditions will apply
- dinner will be provided...
This will be the final class session
except well stretch team size to 1-4 people...
- only written material can be used - only one
machine per team - (we will have a chair for
each team member) - minimal feeback from
submissions - time penalties for incorrect
submssions
29Data Structures
Sep 11 make_pair string Sep 18
map, multimap, set, multiset Sep 25 vector,
deque, list Oct 2 bitset, stack, ... Oct 9
algorithms I Oct 16 algorithms II Oct
23 (fall break) Oct 30 HMC Contest -
900 pm to 100 am ? Nov 6 I/O tips Nov 10
(Sat) -- ACM Contest at Riverside Com. Col. Nov
13 Wrap-up and problem discussion
30printed version after this one
31Welcome to Programming Practicum
Putting the C into CS
University of St. Petersburg
Waiting for the snow enveloping you on Route 5 N
to melt
Engineering dept.
On the 405, in traffic, being chased by police
(and TV) helicopters.
You arent here
writing clinic reports
Lecture
rebooting turing
coding chunky strings
reading requests
clinic liaison phone call
Mailing something at the Claremont Post Office
the dumpster
32What is this course about?
- A chance to improve your C/C
- Problem Insight and Execution ...
- Preparation for the ACM competition ...
Solving problems in teams
- 3 team members, more or less
- 2 problems/week, more or less
- submission through /cs/ACM/acmSubmit
- class web page at www.cs.hmc.edu/ACM
33Grading
P/F by default -- but it can be graded
- 1.75 problems/week gt A
- 1.25 problems/week gt B
- 0.75 problems/week gt C
- 0.25 problems/week gt D
Coding Guidelines
- share coding tasks within teams, not among them
- discussion of algorithms always OK
- start from scratch each time!
34ACM topics
Contest
CS
Topic
Standard Library (STL)
Algorithms/data structures
Overlearning the above
Coding/Contest strategies
35Problems
The digital root problem. (digroot.cc)
starting...
The unscramble problem. (unscramble.cc)
sorting...
The echo problem. (echo.cc)
Input
Intergalactic IRC strings
stdin
hehelllloo spamanyspamone howstheweather
36Problems
The digital root problem. (digroot.cc)
starting...
The unscramble problem. (unscramble.cc)
sorting...
The echo problem. (echo.cc)
Input
Intergalactic IRC strings
stdin
An echo string with buffer size ten
hehelllloo spamanyspamone howstheweather
Not an echo string, but still consistent
Not consistent with the theory
Output
Status Report
stdout
37Resources...
http//www.sgi.com/tech/stl/
Both good overall references
Online STL refs
http//www.dinkumware.com/htm_cpl/index.html
http//www.josuttis.com/libbook/
Example code
Useful stuff for this weeks problems
string t, s Hawaii 2002 getline(cin,t) //
suppose t is Harvey Mudd if (t gt s) //
comparison (, !, ) t i n s
// concatenation s t.substr(7,4) // s
is Mudd s1 // s1 is
u s.length() // returns 4 t.find(a)
// returns 1 (where a is) t.find(a,2) //
returns 16 (starts at 2) // find returns a value
of type stringsize_type // if what is sought
isnt there, find returns stringnpos
string
include ltstringgt
38Resources...
typedef pairltstring, stringgt PS PS mypair
make_pair(hello,world) mypair.first //
these are public members mypair.second struct
MYLESS public lesslt PS gt bool operator()(PS
x,PS y) return x.second lt y.second //
etc. MYLESS mybad PS psArray new
PS1000 // array of PS // putting mybad to
work... sort( psArray, psArrayn ) // default
sort sort( psArray, psArrayn, mybad )
pair
include ltutilitygt
function objects
less
include ltfunctionalgt
sort
include ltalgorithmgt