Fwd: CISC 1110: CodeLab 11187 sort

63 views
Skip to first unread message

Manor Perets

unread,
Nov 30, 2012, 12:03:41 PM11/30/12
to CPP forum

I realized I haven't included my code in my previous email so here it is now. Any help would be appreciated. It compiled properly and output looks good but CodeLab doesn't like it.

I also ran in in a terminal and inspected the output, and it was just my input numbers and followed by one space.
What I am not seeing?
Here is my code and screen shots:

#include <iostream>
using namespace std;

int main(){
int n=11; // number of int to be read in, given. I ran it with various values.
int wasReadIn[50];
// copied to CodeLab from here up to (down to) return 0;
int x, i, j, k; //x will hold value from cin. My compiler allowed me to keep i for all  loops below but showed warning. I guess it's a no no since CodeLab didn't accept it.
for(i=0;i<50;i++) //initilize bool array to false, or int array to zero
wasReadIn[i]=0;
for(j=0;j<n;j++) { //read from cin and increment value of corresponding array element
cin >> x;
wasReadIn[x]++;
}
for(k=0;k<50;k++) // print out in order of array wasReadIn, reiterating for duplicates
while(wasReadIn[k] > 0){
cout << k << " ";
wasReadIn[k]--;
}
return 0;
}

Best wishes,
Manor

Manor Perets

unread,
May 7, 2017, 11:34:30 PM5/7/17
to bc...@googlegroups.com
Hi,
Anyone having problems with this exercise? My output seems good to me, even seems identical to CodeLab's analysis, but it's rejected by CodeLab.
BTW, if you haven't gotten to it yet, note that you do not need to declare an int array, CodeLab declares int wasReadIn[50]. Just take it for granted.

Best wishes,
Manor Perets

Google AppsTM for your business.
undefined



---------- Forwarded message ----------
From: Manor Perets
Date: Fri, Nov 30, 2012 at 1:38 AM
Subject: CISC 1110: CodeLab 11187 sort
To: Professor David Arnow


Hi Professor,
I'm having a hard time with 11187. It seems to me I'm getting the right output on my computer but CodeLab is not accepting it even though it appears to be identical to CodeLab's analysis.

Manor Perets

unread,
May 7, 2017, 11:35:13 PM5/7/17
to bc...@googlegroups.com
Response from the professor.

---------- Forwarded message ----------
From: <arnow
Date: Fri, Nov 30, 2012 at 10:00 AM
Subject: Re: CISC 1110: CodeLab 11187 sort
To: Manor Perets 


IT is fixed. The problem was the exercise had been written
to check the value of wasReadIn as well, and had ssume
that the inner loop would be something like:
for (int q=0; q<wasReadIn[k]; q++)
cout << q << " ";
Your way was legit (though in my opinion not as nice as the above--
after all, you are throwing away information and concealing what is
essentially a counting loop with a testing [while] loop).

But your code DID satisfy our specs, so CodeLab here was WRONG! (yay for you!)

But it's fixed not, try again.

-- David A.
Reply all
Reply to author
Forward
0 new messages