Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 help with bow-tie program
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
limited_skillz




PostPosted: 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)
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
limited_skillz




PostPosted: 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




PostPosted: 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 Laughing
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Andy




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

ya repeat is very helpful
naoki




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

way to spam dodge Evil or Very Mad

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:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: