The SECOND Meeting Or: How I learned exciting new things in CS Club.

Slides:



Advertisements
Similar presentations
Intro to USACO Strategy
Advertisements

Algorithms and Problem Solving
©2004 Brooks/Cole Chapter 3 Interactive Input. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Standard Input and Output System.in Is Used to.
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 4 Object Oriented Programming in Java Class Design Process.
1 Module 2: Fundamental Concepts Problems Programs –Programming languages.
Unit 181 Recursion Definition Recursive Methods Example 1 How does Recursion work? Example 2 Problems with Recursion Infinite Recursion Exercises.
COMP 110 Loops Tabitha Peck M.S. February 11, 2008 MWF 3-3:50 pm Philips
Copyright 2008 by Pearson Education Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: self-check: #16-19.
Writing algorithms using the for-statement. Programming example 1: find all divisors of a number We have seen a program using a while-statement to solve.
Control Structures II. Why is Repetition Needed? There are many situations in which the same statements need to be executed several times. Example: Formulas.
CS 240 – Computer Programming I Lab Kalpa Gunaratna –
COM S 207 While-Loop Statement Instructor: Ying Cai Department of Computer Science Iowa State University
Building Java Programs Chapter 5 Program Logic and Indefinite Loops Copyright (c) Pearson All rights reserved.
1 Course Lectures Available on line:
Iteration and Simple Menus Deterministic / Non-deterministic loops and simple menus.
Methods (Functions) CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Moooooo Or: How I learned to stop worrying and love USACO.
1 Java Console I/O Introduction. 2 Java I/O You may have noticed that all the I/O that we have done has been output The reasons –Java I/O is based on.
Program 6 Any questions?. System.in Does the opposite of System.out.
Computer Science 12 Mr. Jean May 2 nd, The plan: Video clip of the day Review of common errors in programs 2D Arrays.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
Functions Introduction to Programming By Engr. Bilal Ahmad 1ITP by Engr. Bilal Ahmad.
1 Fencepost loops “How do you build a fence?”. 2 The fencepost problem Problem: Write a class named PrintNumbers that reads in an integer called max and.
Please sign in on the sign up sheet MTH Computer Science Club.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
File Input/Output. 2Java Programming: From Problem Analysis to Program Design, 3e File Input/Output File: area in secondary storage used to hold information.
JAVA PROGRAMMING BASICS CHAPTER 2. History of Java Begin with project Green in 1991 founded by Patrick Noughton, Mike Sheridan and James Gosling who worked.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Chapter 6 Programming Languages (1) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Copyright © 2012 Pearson Education, Inc. Chapter 6 More Conditionals and Loops Java Software Solutions Foundations of Program Design Seventh Edition John.
1 while loops. 2 Definite loops definite loop: A loop that executes a known number of times.  The for loops we have seen so far are definite loops. We.
Advanced Computer Science Lesson 4: Reviewing Loops and Arrays Reading User Input.
Java 1.5 The New Java Mike Orsega Central Carolina CC.
CSE 1341 Honors Note Set 05 Professor Mark Fontenot Southern Methodist University.
Data Structures and Algorithm Analysis Introduction Lecturer: Ligang Dong, egan Tel: , Office: SIEE Building.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. A class represents a single concept from the problem domain, or a.
Using the while-statement to process data files. General procedure to access a data file General procedure in computer programming to read data from a.
Click to add title Click to add lame programming pun.
CS 240 – Computer Programming I Lab Kalpa Gunaratna –
Not a Math Honor Society meeting. Or: How I learned to do math again, this time with cows.
CONTROL STATEMENTS LOOPS. WHY IS REPETITION NEEDED?  There are many situations in which the same statements need to be executed several times.  Example:
CSI 3125, Preliminaries, page 1 Java I/O. CSI 3125, Preliminaries, page 2 Java I/O Java I/O (Input and Output) is used to process the input and produce.
CSE 110 Review Session Hans Hovanitz, Kate Kincade, and Ian Nall.
The SECOND Meeting Or: How I learned exciting new things in CS Club.
1 Arrays of Arrays Quick review … arrays Arrays of arrays ≡ multidimensional array Example: times table Representation in memory Ragged arrays Example:
Slides prepared by Rose Williams, Binghamton University Console Input and Output.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Scanner Review Java Foundations: Introduction to Programming and Data Structures.
1 Project 5: Leap Years. 222 Leap Years Write a program that reads an integer value from the user representing a year and determines if the year is a.
JAVA: An Introduction to Problem Solving & Programming, 7 th Ed. By Walter Savitch ISBN © 2015 Pearson Education, Inc., Upper Saddle River,
1 BUILDING JAVA PROGRAMS CHAPTER 5 PROGRAM LOGIC AND INDEFINITE LOOPS.
Chapter 2: Data and Expressions. Variable Declaration In Java when you declare a variable, you must also declare the type of information it will hold.
General Condition Loop A general condition loop just loops while some condition remains true. Note that the body of the loop should (eventually) change.
Introduction to programming in java
IAS 1313: OBJECT ORIENTED PROGRAMMING Week 3: Data Type, Control Structure and Array Prepared by: Mrs Sivabalan1.
Week 9 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
Input/Output.
CSC1401 Input and Output (and we’ll do a bit more on class creation)
Yanal Alahmad Java Workshop Yanal Alahmad
Interactive Standard Input/output
Peer Instruction 9 File Input/Output.
Java Programming: From Problem Analysis to Program Design, 4e
INPUT STATEMENTS GC 201.
Michele Weigle - COMP 14 - Spr 04
Unary Operators ++ and --
Chapter 2: Basic Elements of Java
MSIS 655 Advanced Business Applications Programming
File Handling in Java January 19
CSC1401 Input and Output (with Files)
មជ្ឈមណ្ឌលកូរ៉េ សហ្វវែរ អេច អ ឌី
Presentation transcript:

The SECOND Meeting Or: How I learned exciting new things in CS Club

As you all know… The best way to learn is to do. o It’s true! Thus we will be giving you awesome problems to do o They’re awesome! o There’ll be one each week! o Thus they’re called Problems of the Week! (PotW) Concepts and tricks for USACO and other contests! Prizes!

The PotW Process* Problem presented at meeting o Will be posted online Submit solutions to by 11:59PM the day before the next o Feel free to give any feedback about difficulty o Or suggest your own problems Solution presented at next meeting o Will be posted online after it’s presented See how you and others are doing at lynbrookcs.com! lynbrookcs.com Prizes at end of semester! *subject to change

The Problems Any programming language accepted Graded based on guidelines specified in problem o Officers reserve the right to grade as they please :] Console input/output (System.in, System.out) unless otherwise specified Java input: Use Scanner (easier) or BufferedReader (faster)

Reading Input in JAVA import java.io.*; import java.util.*; Scanner s = new Scanner(System.in); int n = s.nextInt(); BufferedReader r = new BufferedReader( new InputStreamReader(System.in)); int n = Integer.parseInt(r.readLine());

PotW #1: The Ninja Cow Farmer John (get used to the cow theme) has quite a few cows, "conveniently" numbered 1 to N, inclusive. Except, one day, one cow became a ninja and "disappeared" from the herd. Your job is to figure out which cow became a ninja. To avoid arousing the suspicions of the ninja cow, you cannot use arrays, you cannot use longs, and you cannot allow integer overflow. For 10 points, implement your solution for N = 3 For 15 points, implement your solution for 2 ≤ N ≤ 1000 For 20 points, implement your solution for 2 ≤ N ≤ 10 6 Sample Input: Sample Output: 4 (number of cows) 2 (ID of ninja cow) 3 (1st visible cow) 4 (2nd) 1 (etc.)

Hints Note that the input list is not always going to be sorted Note that completing a later task encompasses previous tasks For the first task, “if” statements will work For the second task, calculate the missing cow by using sums o You'll need a "for" loop and a sum variable o Hint: N-1 + N For the third task, you can't use sums anymore because that would overflow an int (and long is not allowed) o The limit of a signed int is o Instead, use the xor operator: “^” instead of “+” o Hint: (a^b)^b always equals a