Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
[CCC 2005] Senior S2 : Mouse Move
Author Message
zylum

Posted: Fri Mar 04, 2005 5:02 pm   Post subject: [CCC 2005] Senior S2 : Mouse Move

[CCC 2005] Senior S2 : Mouse Move

Most likely, you will notice that you have a mouse attached to your computer, which lets you move the cursor around the screen. Your job is to get between the mouse and the cursor.

Suppose that the bottom left-hand corner of your screen is (0,0), and all points on the screen are given by integer co-ordinates (x,y) where 0 <= x <= c and 0 <= y <= r. Thus, the top-right corner of the screen is at position (c,r), bottom-right corner is (c,0), and top-left corner is (0,r).

When a mouse is moved, it sends a pair of integers (a,b), indicating that the cursor should be moved a units in the x-direction and b unites in the y-direction. It is worth noting that this is relative motion (i.e., how for to move) rather than absolute motion (i.e., where to move). It is also worth noting that a and b may be positive, negative or zero.

You can assume the mouse starts at position (0,0). Your job is to read input messages (i.e., relative motion positions sent by the mouse) and update the cursor to the new position on the screen. Your output (to the screen) will be the position of the mouse after each move.

If the mouse hits the screen boundary, it stops moving in that direction. For example, if the mouse is supposed to move (-100,-10) form its curren position (30,40), the final positions will be (0,30): the mouse will hit the left-hand side boundary, but still manages to move down.

Input is listed as pairs, the first pair being (c,r), followed by the relative motion pairs (x,y). The input is terminated when the mouse moves (0,0). The input will be contained in the file s2.in.

Sample Input 1
 code: 100 200 10 40 -5 15 30 -30 0 0

Sample Output ofr Sample Input 1
 code: 10 40 5 55 35 25

Sample Input 2
 code: 30 40 30 40 -100 -10 0 0

Sample Output for Sample Input 2
 code: 30 40 0 30
Sponsor
Sponsor

AlphaWice

Posted: Sun Mar 06, 2005 6:10 pm   Post subject: (No subject)

a joke q, here is the outline of a soln

get c and r

ax = 0, ay = 0
while 1
get rx, ry
if rx = 0 and ry = 0 then break
else ax += rx, ay += ry
if ax<0 then ax = 0
if ax>c then ax = c
if ay<0 then ay = 0
if ay>r then ay = r
print ax, ay
AsianSensation

Posted: Sun Mar 06, 2005 7:11 pm   Post subject: (No subject)

Good job. Now go do the other 4.
thegoose

Posted: Mon Mar 07, 2005 7:04 am   Post subject: (No subject)

AsianSensation wrote:
Good job. Now go do the other 4.

Eh.....he did have a higher score than most people on this forum.....
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 4 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: