my program which for some reason does not work. |
That's not a very helpful explanation of your problem.
What happens?
i don't get why the site of our university does not approve of it |
Not sure that I believe that; your code is (presumably) in a file after all. Sounds like you might be unable to find and/or read your input file. Put
if ( !dat ) { cout << "Can't open file"; return 1; }
after line 16 and make sure that you can actually read the file.
To be honest, I can't work out what your code is trying to do, and there are some issues in your description of the problem. However, from the sample input and output it looks like:
"At the end, output each integer present in the array and the number of lines it occurs in".
Please confirm.
There's obviously a significant issue with duplicates - see the second example.
If my interpretation is correct, here's a suggestion (after you've checked that you can open the data file).
- Have a map<int,int> to hold the distinct elements and the cumulative number of lines they are present in.
- Go through the data file row by row.
- On each row, use a set<int> to hold the distinct integers.
- After assembling this set of distinct integers, compare each element with those in the map. Add one to the line count for each element already in the map, or a new element with line count 1 if not already in the map.
- Clear the set before going to the next row.
It's very different from your code, so if you want to use your code instead ... please put some comments in to explain what it is trying to to do.