Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
help with bow-tie program
Author Message
limited_skillz

Posted: Mon Feb 23, 2004 12:05 am   Post subject: help with bow-tie program

i was practicing some of the previous computing competitions and i am stumped by the first question in the 2001 one

For this question, you will write a program to print out a bow tie on the computer screen.

Your program should take as input the height H of the bow tie, where H is an odd positive integer greater than or equal to 5. A bow tie with H rows (and 2H columns) should then be printed using the pattern shown below. You may assume that all input data will be valid.

For this question you should read the input from the keyboard and print the output to the screen.

Sample Session: (User input is in italics.)

Enter height:
5
*-----------*
***-----***
**********
***-----***
*-----------*

Enter height:
7
*-----------------*
***----------***
*****---- *****
**************
*****---- *****
*** ---------***
*--------------- *

- = blank space

i cant even think up a way to do it for the other side, but i do have one side right

 code: View.Set ("graphics:640;480,nocursor") proc drawTie (h, x, y : int)     if h > 0 then         locatexy (x, y)         for i : 1 .. 2 * h - 1             put "*" ..         end for         drawTie (h div 2, x, y + 15)         drawTie (h div 2, x, y - 15)     end if end drawTie % main var h : int loop     put "Height of bowtie (must be odd, positive integer greater or equal to 5): " ..     get h     exit when h >= 5 and h mod 2 not= 0     cls end loop cls drawTie (h , 250, 315)

Tony

Posted: Mon Feb 23, 2004 12:15 am   Post subject: (No subject)

its very simple
 code: var size:int put "what size?" get size for i:1..floor(size/2) put repeat("*",i),repeat(" ",size-i*2),repeat("*",i) end for put repeat("*",size) for decreasing i : floor(size/2)..1 put repeat("*",i),repeat(" ",size-i*2),repeat("*",i) end for
Tony's programming blog. DWITE - a programming contest.
limited_skillz

Posted: Mon Feb 23, 2004 12:38 am   Post subject: (No subject)

thanks a lot man, i still dont understand lol, illl spend the next half hour figuring it out

my brain is just trying to act too complex, im here trying to use recursion and trying to find some sort of formula whether to print or not

i even tried to see if area was involved

man do i need to simplify things

-edit - oh i didnt know repeat existed, hm, this shouldnt have wasted so much of my time
Tony

Posted: Mon Feb 23, 2004 10:23 am   Post subject: (No subject)

lol, recursion? you should know better then that, isn't this a J1 question? lol
Tony's programming blog. DWITE - a programming contest.
Andy

Posted: Mon Feb 23, 2004 10:35 am   Post subject: (No subject)

naoki

Posted: Mon Feb 23, 2004 4:32 pm   Post subject: (No subject)

way to spam dodge

anyways you could even shorten tony's code by doing a normal for loop, from 1 to H. I kept a counter which I set to 2 or -2. I change it to -2 when I'm unable to repeat any spaces (using a simple subtraction to figure out my spaces). When I can't output spaces, that means that my bowtie is shrinking and thus I change my counter.

The counter is added to my repeat function for the *'s before and after the spaces
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 6 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: