Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. For all you C# geeks: Knock yourselves out [modified]

For all you C# geeks: Knock yourselves out [modified]

Scheduled Pinned Locked Moved C#
questioncsharpc++javatesting
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bulky Fellow
    wrote on last edited by
    #1

    My office is testing a bunch of folks who have applied for Java jobs. I don't know head and tails of the language other than that its syntax is stolen from here and there (I'm still partyin' with MFC/Win32, yay!). My buddy was the invigilator and got the questions' sheet. This was one of the easiest assignments, and shockingly, only 3 out of the 14 people that attempted this problem finished it correctly on time. Some took more than 45 minutes but got it right, and others didn't solve it at all! I tried it for the hell of it beat the time by 29 minutes, finishing at 16 minutes (C/DevCPP), which I guess is not bad. Post your times here, and see if you can bring it down below 16 minutes. ;)

    Q7. (Note: You cannot answer Questions 8, 11 and 14 if you are answering this question. Pick another 2 from the rest).
    Write a command-line program as follows:

    First the program will take as input a +ve integer from the user, let's call it
    the TARGET.

    It will then take in a set of +ve integers from the user, and here the user gets
    to specify how many integers he/she wants to enter. Let's call this set the
    RANGE.

    Now the program should compute as follows:

    • Find all combinations in the RANGE, the sum of which add up to the
      target. Print such combinations at the command prompt. In a combination,
      repeats are not allowed. i.e. (x + x + y) = TARGET is forbidden. Every element
      in the combination must be unique.

    • In case a user enters a RANGE element greater than the target, it should be immediately
      discarded and the user must be prompted for the element again.

    • Order shifted cases don't count. i.e. (x+y) and (y+x) being printed
      separately is unnecessary and MUST be avoided.

    • In case no combinations exist, the program should report so.

    • Add exception handling code where necessary.

    Example Run:

    Enter Target: 15
    How many set elements?: 5
    Enter Element1: 7
    Enter Element2: 8
    Enter Element3: 12
    Enter Element4: 3
    Enter Element5: 22
    Sorry. That element is larger than your target. Try again.
    Enter Element5: 4

    Combinations are:
    1] 7+8
    2] 8+3+4
    3] 12+3

    Time: 45 mins.

    (At the top of the source file, please comment in your ID details along with the reference number at the back of the day-card you were provided by the examiner. Write your Full Name, ID key, TDC number and most importantly the reference number. Good luck.)

    modified on Tuesday, November 4, 2008 2:13 PM

    G M 2 Replies Last reply
    0
    • B Bulky Fellow

      My office is testing a bunch of folks who have applied for Java jobs. I don't know head and tails of the language other than that its syntax is stolen from here and there (I'm still partyin' with MFC/Win32, yay!). My buddy was the invigilator and got the questions' sheet. This was one of the easiest assignments, and shockingly, only 3 out of the 14 people that attempted this problem finished it correctly on time. Some took more than 45 minutes but got it right, and others didn't solve it at all! I tried it for the hell of it beat the time by 29 minutes, finishing at 16 minutes (C/DevCPP), which I guess is not bad. Post your times here, and see if you can bring it down below 16 minutes. ;)

      Q7. (Note: You cannot answer Questions 8, 11 and 14 if you are answering this question. Pick another 2 from the rest).
      Write a command-line program as follows:

      First the program will take as input a +ve integer from the user, let's call it
      the TARGET.

      It will then take in a set of +ve integers from the user, and here the user gets
      to specify how many integers he/she wants to enter. Let's call this set the
      RANGE.

      Now the program should compute as follows:

      • Find all combinations in the RANGE, the sum of which add up to the
        target. Print such combinations at the command prompt. In a combination,
        repeats are not allowed. i.e. (x + x + y) = TARGET is forbidden. Every element
        in the combination must be unique.

      • In case a user enters a RANGE element greater than the target, it should be immediately
        discarded and the user must be prompted for the element again.

      • Order shifted cases don't count. i.e. (x+y) and (y+x) being printed
        separately is unnecessary and MUST be avoided.

      • In case no combinations exist, the program should report so.

      • Add exception handling code where necessary.

      Example Run:

      Enter Target: 15
      How many set elements?: 5
      Enter Element1: 7
      Enter Element2: 8
      Enter Element3: 12
      Enter Element4: 3
      Enter Element5: 22
      Sorry. That element is larger than your target. Try again.
      Enter Element5: 4

      Combinations are:
      1] 7+8
      2] 8+3+4
      3] 12+3

      Time: 45 mins.

      (At the top of the source file, please comment in your ID details along with the reference number at the back of the day-card you were provided by the examiner. Write your Full Name, ID key, TDC number and most importantly the reference number. Good luck.)

      modified on Tuesday, November 4, 2008 2:13 PM

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Maybe I made too much work on the UI, handling non-numeric input and such... The input part is exactly half the program. 27 minutes. :)

      Despite everything, the person most likely to be fooling you next is yourself.

      1 Reply Last reply
      0
      • B Bulky Fellow

        My office is testing a bunch of folks who have applied for Java jobs. I don't know head and tails of the language other than that its syntax is stolen from here and there (I'm still partyin' with MFC/Win32, yay!). My buddy was the invigilator and got the questions' sheet. This was one of the easiest assignments, and shockingly, only 3 out of the 14 people that attempted this problem finished it correctly on time. Some took more than 45 minutes but got it right, and others didn't solve it at all! I tried it for the hell of it beat the time by 29 minutes, finishing at 16 minutes (C/DevCPP), which I guess is not bad. Post your times here, and see if you can bring it down below 16 minutes. ;)

        Q7. (Note: You cannot answer Questions 8, 11 and 14 if you are answering this question. Pick another 2 from the rest).
        Write a command-line program as follows:

        First the program will take as input a +ve integer from the user, let's call it
        the TARGET.

        It will then take in a set of +ve integers from the user, and here the user gets
        to specify how many integers he/she wants to enter. Let's call this set the
        RANGE.

        Now the program should compute as follows:

        • Find all combinations in the RANGE, the sum of which add up to the
          target. Print such combinations at the command prompt. In a combination,
          repeats are not allowed. i.e. (x + x + y) = TARGET is forbidden. Every element
          in the combination must be unique.

        • In case a user enters a RANGE element greater than the target, it should be immediately
          discarded and the user must be prompted for the element again.

        • Order shifted cases don't count. i.e. (x+y) and (y+x) being printed
          separately is unnecessary and MUST be avoided.

        • In case no combinations exist, the program should report so.

        • Add exception handling code where necessary.

        Example Run:

        Enter Target: 15
        How many set elements?: 5
        Enter Element1: 7
        Enter Element2: 8
        Enter Element3: 12
        Enter Element4: 3
        Enter Element5: 22
        Sorry. That element is larger than your target. Try again.
        Enter Element5: 4

        Combinations are:
        1] 7+8
        2] 8+3+4
        3] 12+3

        Time: 45 mins.

        (At the top of the source file, please comment in your ID details along with the reference number at the back of the day-card you were provided by the examiner. Write your Full Name, ID key, TDC number and most importantly the reference number. Good luck.)

        modified on Tuesday, November 4, 2008 2:13 PM

        M Offline
        M Offline
        Mark Churchill
        wrote on last edited by
        #3

        You should stick this over in Math & Algs. The interesting bit here is how your candidates go about solving the subset-sum problem, which is NP-Complete. The input half would be done in first year uni.

        Mark Churchill Director, Dunn & Churchill Pty Ltd Free Download: Diamond Binding: The simple, powerful, reliable, and effective data layer toolkit for Visual Studio.
        Alpha release: Entanglar: Transparant multiplayer framework for .Net games.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups