CrazyEngineers
  • 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
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Ashraf HZ

    MemberSep 21, 2008

    [spam]
    *quickly closes Google Search*

    uh.. say what? 😛

    It'll be interesting to code this in a language you are not familiar with 😀
    [/spam]
    Are you sure? This action cannot be undone.
    Cancel
  • gaurav.bhorkar

    MemberSep 22, 2008

    I do not know any computer language as I am in 1st year but still, i will try using HTML code and JavaScript.

    <html>
    <body>
    <script language="JavaScript">
    a=parse(prompt("text here"));
    document.write(+a);
    document.write(+"1: Hello, this is The Big K");
    document.write(+"2: This is line number 2");
    document.write(+"3: ___");
    </script>
    </body>
    </html>


    I guess it is correct.
    Are you sure? This action cannot be undone.
    Cancel
  • chtn

    MemberSep 22, 2008

    hey can u select one best project in electronics
    Are you sure? This action cannot be undone.
    Cancel
  • Kaustubh Katdare

    AdministratorSep 22, 2008

    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.

    <html>
    <body>
    <script language="JavaScript">
    a=parse(prompt("text here"));
    document.write(+a);
    document.write(+"1: Hello, this is The Big K");
    document.write(+"2: This is line number 2");
    document.write(+"3: ___");
    </script>
    </body>
    </html>

    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?
    Are you sure? This action cannot be undone.
    Cancel
  • Kaustubh Katdare

    AdministratorSep 22, 2008

    Hah!

    Guys! This one is simple! I want the code! Right NOW! [​IMG]
    Are you sure? This action cannot be undone.
    Cancel
  • gaurav.bhorkar

    MemberSep 23, 2008

    Can anyone display this :

    *
    **
    ***
    ****
    *****
    Are you sure? This action cannot be undone.
    Cancel
  • niraj.kumar

    MemberSep 23, 2008

    Gaurav this is very simple but good for newbie to computer science this problem should be like this
    *
    ***
    *****
    *******
    Are you sure? This action cannot be undone.
    Cancel
  • Kaustubh Katdare

    AdministratorSep 23, 2008

    I want the first problem to be cracked! No one yet?
    Are you sure? This action cannot be undone.
    Cancel
  • anuragh27crony

    MemberSep 24, 2008

    Does the line numbers...include Input...????
    Are you sure? This action cannot be undone.
    Cancel
  • Raviteja.g

    MemberSep 25, 2008

    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());
    }
    }
    Are you sure? This action cannot be undone.
    Cancel
  • sriramchandrk

    MemberSep 26, 2008

    😔
    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 -
    <Text string Input>

    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 <iostream>
    #include <vector>
    #include <algorithm>
    using namespace std;
    int main()
    {
    char inp[255];
    int i = 0;
    vector<string> 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<string>::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
    Are you sure? This action cannot be undone.
    Cancel
  • crazypooh

    MemberOct 5, 2008

    k the problem is not tough but 1 confusion that what do u mean by reversing the words??????
    Are you sure? This action cannot be undone.
    Cancel
  • crazypooh

    MemberOct 5, 2008

    #include<iostream.h>
    #include<conio.h>
    #include<stdio.h>
    void main()
    {
    Are you sure? This action cannot be undone.
    Cancel
  • Kaustubh Katdare

    AdministratorOct 5, 2008

    Please read the question again. I've provided sample input/output. That should be enough to give you a hint.
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register