Programming exercise for newbies

Here's a small coding exercise for programming newbies. I asked this question in an interview to a computer science graduate and she could not solve it. It was surprizing. The computer science, IT engineers should start thinking on their own - mugging up the stuff from book doesn't help.

So here's a simple programming challenge [for newbies]:-

Write a program that accepts a new text strings, one on each line, but prints a line number before it accepts the input. The lines are then printed out, with each word individually reversed.

That is, the output should look like -


1: Hello, this is The Big K
2: This is line number 2
3: ___

*******************************
1: K giB ehT siht ,olloeH

etc.

I hope you got the problem. Use any damn computer programming language of your choice. The only bet is - you crack this question on your own. The purpose is to make you think, not to test your Google search skills.

All the best.

[Provide all details in comments inside your code]

Replies

  • Ashraf HZ
    Ashraf HZ
    [spam]
    *quickly closes Google Search*

    uh.. say what? ๐Ÿ˜›

    It'll be interesting to code this in a language you are not familiar with ๐Ÿ˜€
    [/spam]
  • gaurav.bhorkar
    gaurav.bhorkar
    I do not know any computer language as I am in 1st year but still, i will try using HTML code and JavaScript.








    I guess it is correct.
  • chtn
    chtn
    hey can u select one best project in electronics
  • Kaustubh Katdare
    Kaustubh Katdare
    gaurav.bhorkar
    I do not know any computer language as I am in 1st year but still, i will try using HTML code and JavaScript.







    I guess it is correct.
    Wow! I never expected such a simple solution! ๐Ÿ˜

    I guess another simple solution would be to use "printf" or "cout" keywords to generate the output. Right?
  • Kaustubh Katdare
    Kaustubh Katdare
    Hah!

    Guys! This one is simple! I want the code! Right NOW! [โ€‹IMG]
  • gaurav.bhorkar
    gaurav.bhorkar
    Can anyone display this :

    *
    **
    ***
    ****
    *****
  • niraj.kumar
    niraj.kumar
    Gaurav this is very simple but good for newbie to computer science this problem should be like this
    *
    ***
    *****
    *******
  • Kaustubh Katdare
    Kaustubh Katdare
    I want the first problem to be cracked! No one yet?
  • anuragh27crony
    anuragh27crony
    Does the line numbers...include Input...????
  • Raviteja.g
    Raviteja.g
    sorry for the late respose i am writing the code in java hope this is correct if i am wrong please correct me.
    import java.io.*;
    class rev
    {public static void main(String args[])
    {
    InputStreamReader isr=new InputStreamReader(System.in);
    BufferedReader br =new BufferedReader(isr);
    String s;
    System.out.println("input the string");
    System.out.println("the line number is two");
    s=br.readline;
    System.out.println(s.reverse());
    }
    }
  • sriramchandrk
    sriramchandrk
    ๐Ÿ˜”
    The_Big_K
    Here's a small coding exercise for programming newbies. I asked this question in an interview to a computer science graduate and she could not solve it. It was surprizing. The computer science, IT engineers should start thinking on their own - mugging up the stuff from book doesn't help.

    So here's a simple programming challenge [for newbies]:-

    Write a program that accepts a new text strings, one on each line, but prints a line number before it accepts the input. The lines are then printed out, with each word individually reversed.

    That is, the output should look like -


    1: Hello, this is The Big K
    2: This is line number 2
    3: ___

    *******************************
    1: K giB ehT siht ,olloeH

    etc.

    I hope you got the problem. Use any damn computer programming language of your choice. The only bet is - you crack this question on your own. The purpose is to make you think, not to test your Google search skills.

    All the best.

    [Provide all details in comments inside your code]
    This work's is this what you wanted?
    #include
    #include
    #include
    using namespace std;
    int main()
    {
    char inp[255];
    int i = 0;
    vector inpTxt;
    string str;
    cout << "Input lines to stop input 'end'" << endl;
    while(strcmp(inp,"end"))
    {
    cout << ++i << ":" ;
    cin.getline(inp, 255);
    str.assign(inp);
    reverse(str.begin(), str.end());
    inpTxt.push_back(str);
    }
    cout << endl << "Reversed Output" << endl;
    for(vector::iterator it = inpTxt.begin(); it!= inpTxt.end(); it++)
    cout << (*it).c_str() << endl;
    }

    ==== TEST RUN =====
    Input lines to stop input 'end'
    1:who is this
    2:i am not going to see google
    3:i remember few things
    4:bye
    5:end
    Reversed Output
    siht si ohw
    elgoog ees ot gniog ton ma i
    sgniht wef rebmemer i
    eyb
    dne


    Regards
    Sriram
  • crazypooh
    crazypooh
    k the problem is not tough but 1 confusion that what do u mean by reversing the words??????
  • crazypooh
    crazypooh
    #include
    #include
    #include
    void main()
    {
  • Kaustubh Katdare
    Kaustubh Katdare
    Please read the question again. I've provided sample input/output. That should be enough to give you a hint.

You are reading an archived discussion.

Related Posts

Let's brainstorm on this one. I came across an old guy who was pulling his cycle rickshaw because he had no energy to peddle. I started thinking if we could...
Hi i own a website , I want to add free SMS from my website Remember i don't talk for 160by2 or other SMS provider's Application but i need own...
So will this crazy tee shirts be available for us?
๐Ÿ˜ Taking a cue from Biggie's hourly update, here is my narration of the CE meet. About 2:30pm, CEan Mayur Pathak climbs a fast local to Churchgate. He is going...
I am nice to be here...