Computer Science Canada String Problem |
Author: | Jurica [ Mon Nov 10, 2008 4:23 pm ] |
Post subject: | String Problem |
Alright having problems with string now, tried to do it but couldn't figure it out. I've done some of it but not all of it. Question: Write a Turing program that accepts a word typed at the keyboard. Your program will then create the pattern illustrated like this one: word o__ r r__ o Ignore the ___'s. drow var word : string % Tells you to enter a word put "Enter word: " .. get word % Determines how much letters are in the words put word, " has ", length (word), " letters." put "" % Top row % Right row % Bottom row % Left row for i : 1 .. length (word) put word (i) end for |
Author: | OneOffDriveByPoster [ Mon Nov 10, 2008 4:34 pm ] | ||||
Post subject: | Re: String Problem | ||||
You can use code tags:
gets you
Anyhow, the first and last rows are obvious. The middle rows will follow a pattern: (2nd letter) ((length - 2) spaces) (2nd-to-last letter), etc. |
Author: | Jurica [ Mon Nov 10, 2008 4:38 pm ] |
Post subject: | RE:String Problem |
Said there were 3 errors, and 2 warnings. |
Author: | Jurica [ Mon Nov 10, 2008 4:45 pm ] |
Post subject: | RE:String Problem |
Okay, got it. But they put a random word, so it won't be the letter word that will be there, can be anything. |
Author: | OneOffDriveByPoster [ Mon Nov 10, 2008 4:48 pm ] |
Post subject: | Re: RE:String Problem |
Jurica @ Mon Nov 10, 2008 4:45 pm wrote: Okay, got it. But they put a random word, so it won't be the letter word that will be there, can be anything. What I said applies to any input string. You need a loop for the middle rows. Follow the pattern and you will know what to put inside the loop. |
Author: | Jurica [ Tue Nov 11, 2008 3:37 pm ] | ||
Post subject: | RE:String Problem | ||
Okay, I finished it. The code to do it is:
|
Author: | Jurica [ Tue Nov 11, 2008 3:38 pm ] | ||
Post subject: | RE:String Problem | ||
Opps, made a mistake. Here's the right one:
|