Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,191,007 members, 7,942,624 topics. Date: Saturday, 07 September 2024 at 01:34 PM |
Nairaland Forum / Science/Technology / Programming / Sorting List Of Numbers And Strings: Simple Puzzle (9489 Views)
Sorting Out A Simple Text Dictionary With PHP / Sorting Algorithms / How To Sorting Tables With Vb.6 (2) (3) (4)
Sorting List Of Numbers And Strings: Simple Puzzle by ektbear: 12:20am On Nov 09, 2012 |
I came across this a few weeks ago. Here is how it goes: ----------------- You are to write a program that takes a list of strings containing integers and words and returns a sorted version of the list. The goal is to sort this list in such a way that all words are in alphabetical order and all integers are in numerical order. Furthermore, if the nth element in the list is an integer it must remain an integer, and if it is a word it must remain a word. Input: ------ The input will contain a single, possibly empty, line containing a space-separated list of strings to be sorted. Words will not contain spaces, will contain only the lower-case letters a-z. Integers will be in the range -999999 to 999999, inclusive. The line will be at most 1000 characters long. Output: ------- The program must output the list of strings, sorted per the requirements above. Strings must be separated by a single space, with no leading space at the beginning of the line or trailing space at the end of the line. Constraints: ------------ The code you submit must take input from stdin and produce output to stdout as specified above. No other output is permitted. You can assume the input will be valid. Feel free to use standard libraries to assist in sorting. In the examples below, the text "Input:" and "Output:" are not part of the output, and neither are the blank lines. Example 4: ---------- Input: car truck 8 4 bus 6 1 Output: bus car 1 4 truck 6 8 |
Re: Sorting List Of Numbers And Strings: Simple Puzzle by lordZOUGA(m): 10:08am On Nov 09, 2012 |
can we use the C++ STL |
Re: Sorting List Of Numbers And Strings: Simple Puzzle by ektbear: 10:10am On Nov 09, 2012 |
fo sho i did it using ruby, then converted to java using java collections library for further context, the idea is to solve this puzzle in ideally 30 minutes or so...so no need to implement sorting from scratch. Using standard library stuff as a building block. |
Re: Sorting List Of Numbers And Strings: Simple Puzzle by PrinceNN(m): 6:18pm On Nov 10, 2012 |
Re: Sorting List Of Numbers And Strings: Simple Puzzle by Javanian: 8:53pm On Nov 10, 2012 |
|
Re: Sorting List Of Numbers And Strings: Simple Puzzle by idesignwebsite(m): 10:35pm On Nov 10, 2012 |
Javanian:Helo J help my ignorance,what is the code suppose to solve better still what is the algorithm like..ur olodo student..abeg no vex I don see say na sort you dey sort |
Re: Sorting List Of Numbers And Strings: Simple Puzzle by Javanian: 1:02am On Nov 11, 2012 |
^^^ sorry, what part of the code do you have problem with? |
Re: Sorting List Of Numbers And Strings: Simple Puzzle by Javanian: 6:45am On Nov 11, 2012 |
Where is @ekt_bear?? |
Re: Sorting List Of Numbers And Strings: Simple Puzzle by PrinceNN(m): 7:54am On Nov 11, 2012 |
Javanian: Where is @ekt_bear??Beats mee... |
Re: Sorting List Of Numbers And Strings: Simple Puzzle by Javanian: 12:22pm On Nov 12, 2012 |
@ekt_bear we go fry egg for you |
Re: Sorting List Of Numbers And Strings: Simple Puzzle by ektbear: 2:47pm On Nov 12, 2012 |
Re: Sorting List Of Numbers And Strings: Simple Puzzle by Javanian: 7:00am On Nov 13, 2012 |
Can i see your java implementation? |
Re: Sorting List Of Numbers And Strings: Simple Puzzle by ektbear: 7:34am On Nov 13, 2012 |
Fo sho I'll post it when I get home |
Re: Sorting List Of Numbers And Strings: Simple Puzzle by ektbear: 8:01am On Nov 13, 2012 |
Here is my java version: http://pastebin.com/DwVpvzAs |
Re: Sorting List Of Numbers And Strings: Simple Puzzle by Javanian: 8:11am On Nov 13, 2012 |
Nice one...quite similar to mine... |
Re: Sorting List Of Numbers And Strings: Simple Puzzle by ektbear: 8:17am On Nov 13, 2012 |
Yep....pretty much just a direct translation of my ruby code. |
Re: Sorting List Of Numbers And Strings: Simple Puzzle by NoiseMaker1: 1:40pm On Jan 03, 2013 |
. |
Re: Sorting List Of Numbers And Strings: Simple Puzzle by NoiseMaker1: 1:42pm On Jan 03, 2013 |
₱®ÌИСΞ:is it a website |
Re: Sorting List Of Numbers And Strings: Simple Puzzle by Nobody: 2:10pm On Jan 03, 2013 |
Biko warris this doing on the FP? |
Re: Sorting List Of Numbers And Strings: Simple Puzzle by jacob05(m): 6:43pm On Jan 03, 2013 |
@lordZOUGA i hail ooooo I'm Quite new to C/C++ but here is my lengthy version...
|
Re: Sorting List Of Numbers And Strings: Simple Puzzle by jacob05(m): 6:46pm On Jan 03, 2013 |
Paste bin : http://pastebin.com/hwt22dap |
Re: Sorting List Of Numbers And Strings: Simple Puzzle by fola14: 7:34pm On Jan 03, 2013 |
Hello, I am interested in programming, who can help me out. I have very little experience in it and I would be willing to know more. How can I start? |
Re: Sorting List Of Numbers And Strings: Simple Puzzle by eaglechild: 10:38pm On Jan 03, 2013 |
brokoto: Biko warris this doing on the FP?It tells the world that Nigerians are smart too. Guess that's what the mod was thinking. Though he forgot how very esoteric the topic is. |
Re: Sorting List Of Numbers And Strings: Simple Puzzle by Javanian: 10:50pm On Jan 03, 2013 |
eaglechild: Everything on Planet Earth is Esoteric... |
Re: Sorting List Of Numbers And Strings: Simple Puzzle by lordZOUGA(m): 11:17pm On Jan 03, 2013 |
@jacob05, nice one boss. Seems as if you learnt coding with "C++ cookbook"... You can do better though |
Re: Sorting List Of Numbers And Strings: Simple Puzzle by Nobody: 11:59pm On Jan 03, 2013 |
Re: Sorting List Of Numbers And Strings: Simple Puzzle by jacob05(m): 12:30am On Jan 04, 2013 |
lordZOUGA: @jacob05, nice one boss. Seems as if you learnt coding with "C++ cookbook"... You can do better thoughyes boss |
Re: Sorting List Of Numbers And Strings: Simple Puzzle by InvertedHammer: 4:18am On Jan 04, 2013 |
This is a programming question for beginners! Nice try though |
Re: Sorting List Of Numbers And Strings: Simple Puzzle by pak: 4:45am On Jan 04, 2013 |
ekt_bear, I feel like punching you for depriving me of my sleep really. Saw this as I was about to hit the sack and couldn't blink until I cracked it. My fav pastime is Python but since I dont us python in my day job, I've been terribly rusty. Infact the stuff took me well over an hour considering I was even just installing the python executable on my new sis. However, having lost out in the competition to be the fastest, I strove for the next glorious crown - to be the most elegant Guess I achieved it. 19 lines of code Prince actually did the stuff in 18 lines (with the white spaces stripped of) but the script didn't run when I tried it out. I guess he has to check out one or two stuffs in the code. . . .and the Java solutions ? puleeeeeeeeaaaaaaaaaase. is that the code to calculate the GDP of Nigeria ? Really, I appreciate you guys (the programmers) but its the lang that I detest. To The C++ guy, I believe C++ can do better than that, That was actually my first love. but kudos though. Check out my solution http://pastebin.com/W3swZVfd |
Lets Learn C / How Do I Edit Datagrid ? / How Do You Get A CEH / Pentesting Job In Nigeria?
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 42 |