You are not logged in. Please login at www.codechef.com to post your questions!

×

Is there something wrong with the following solution to the "Bytelandian gold coins" problem.

Okay, so here's my solution to the "Bytelandian gold coins" problem.

#include <iostream>

using namespace std;

int main()
{
    unsigned int n;
    unsigned int n_dollars;


    int i = 0;
    while(i < 8)
    {
        cin >> n;

        if(n>=1000000000 || n<=0)break;

        n_dollars = (13 * n)/12;
        cout << n_dollars << endl << endl;
    }

    return 0;
}

But when I submit this program, it says "Time Limit Exceeded". Clearly the above solution does work fine. And I think that this solution is pretty fast. Is there something wrong with my solution or isn't there ?

Thanks, Best Regards !

asked 24 Apr '14, 16:46

pravinda333's gravatar image

0★pravinda333
11
accept rate: 0%


Have a look at this i just entered 2 numbers in the input and it printed so many outputs.

Also the output was not formatted as required. Before discussing this question, i would suggest that you first have a look at these:
TEST and HS08TEST

link

answered 24 Apr '14, 17:02

roman28's gravatar image

4★roman28
1.6k71429
accept rate: 19%

edited 24 Apr '14, 17:05

@pravinda333 you have not incremented your variable i which is why your code never exits the while loop. use: while(i<8) { ... i++ }

link

answered 21 Jun '14, 06:08

ironmandhruv's gravatar image

4★ironmandhruv
333239
accept rate: 20%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×646
×86
×12

question asked: 24 Apr '14, 16:46

question was seen: 785 times

last updated: 21 Jun '14, 06:08