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

Username:   Password: 
 RegisterRegister   
 [CCC 2005] Senior S1 : Snow Calls
Index -> Contests
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
zylum




PostPosted: Fri Mar 04, 2005 4:46 pm   Post subject: [CCC 2005] Senior S1 : Snow Calls

[CCC 2005] Senior S1 : Snow Calls

You've been snowed in at your summer residence. And without the Internet! Unfornutanetly, this means you're going to have to rely on using the phone to get what you need to survive: pizza, pop, and the latest video games.

Often times, companies replace the digits in their phone numbers with characters to make their phone numbers more memorable. Because apparently, it's easier to remember 416-BUY-MORE than it is to remember 416-289-6673. Some campanies even add extra digits or characters (like 604-PIZZABOX) but any digits after the 10th are irrelevant.

Since it's getting tedious to do the conversion by hand, write a program to help change all the phone numbers in your phone book to the form xxx-xxx-xxxx, using the below image to assist you.

code:
______ _____ _____
|  1  |  2  |  3  |
|     | ABC | DEF |
|_____|_____|_____|
|  4  |  5  |  6  |
| GHI | JKL | MNO |
|_____|_____|_____|
|  7  |  8  |  9  |
| PQRS| TUV |WXYZ |
|_____|_____|_____|


Input
Input consists of a series of test cases. The first line consists of an integer t, the number of test cases. Following are t lines consisting of alpha-numeric characters separated by hyphens, representing valid phone numbers. No line is longer than 40 characters. Input will be contained in the file s1.in.

Output
For each test case, output the phone number in hte form xxx-xxx-xxxx to the screen.

Sample Input
code:
5
88-SNOW-5555
519-888-4567
BUY-MORE-POP
416-PIZZA-BOX
5059381123


Sample Output
code:
887-669-5555
519-888-4567
289-6673767
416-749-9226
505-983-1123
Sponsor
Sponsor
Sponsor
sponsor
rizzix




PostPosted: Fri Mar 04, 2005 5:03 pm   Post subject: (No subject)

This can be solved using a oneliner (more-or-less) in java using regex. obviously thats not allowed right? heh.
zylum




PostPosted: Fri Mar 04, 2005 5:15 pm   Post subject: (No subject)

ofcourse it's allowed Wink
Tony




PostPosted: Fri Mar 04, 2005 5:25 pm   Post subject: (No subject)

Ruby:

puts "enter your a phone number"
phone = gets.chomp
phone = phone.gsub("-","")[0..9]
phone.gsub!(/[a-c]/i,"2")
phone.gsub!(/[d-f]/i,"3")
phone.gsub!(/[g-i]/i,"4")
phone.gsub!(/[j-l]/i,"5")
phone.gsub!(/[m-o]/i,"6")
phone.gsub!(/[p-s]/i,"7")
phone.gsub!(/[t-v]/i,"8")
phone.gsub!(/[w-z]/i,"9")
puts phone[0..2] + "-" + phone[3..5] + "-" + phone[6..9]

I know there's a much more eligant way of doing this, but since the contest is time limited, copy/paste of very simple regex's will have you working on S2 within seconds Wink
rizzix




PostPosted: Fri Mar 04, 2005 5:33 pm   Post subject: (No subject)

yea but tony the contest does not permit Ruby. Wink or does it? Confused
Hikaru79




PostPosted: Fri Mar 04, 2005 6:49 pm   Post subject: (No subject)

rizzix wrote:
yea but tony the contest does not permit Ruby. Wink or does it? Confused

I'm pretty sure the CCC allows anything your school is making available (Round 2 is much more restrictive though). Of course, good luck finding a school that has Ruby...
Tony




PostPosted: Fri Mar 04, 2005 9:18 pm   Post subject: (No subject)

rizzix wrote:
yea but tony the contest does not permit Ruby.

Stage 1 of CCC allows vertually any language other than some specialized ones such as Maple. I'm pretty sure that has to do with the fact that Maple has most of math algorythms build in.

Stage 2 is limited to a select few (C++, Java, Pascal and Turing I belive... Somebody would have to confirm that), but only because University computers are used, and they can't be bothered with installing and configuring all of those compilers.

Hikaru79 : like any good programming language, Ruby is free to download and use
Display posts from previous:   
   Index -> Contests
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: