|
|
back to boardTest 1 Can anybody give me the test case 1? Re: Test 1 Have you tried task example? ---- 3 6 1 2 3 2 1 1 --- Have you received the same output as in example? --- 50.00% 33.33% 16.67% --- Re: Test 1 Yes, my code gives the same output for sample test case. Here is my code- #include <iostream> #include<iomanip> using namespace std;
int main() { int n, m, vote; cin>>n>>m; int *candidates = new int[n]; for(int i=0; i<m; i++) { cin>>vote; candidates[vote-1]++; }
for(int j=0; j<n; j++) { cout<<fixed<<setprecision(2)<<float(float(candidates[j]*100)/m)<<"%"<<endl; }
return 0; } Edited by author 01.03.2016 10:07 Re: Test 1 1) What is initial value for "candidates" items? Isn't it undefined? 2) Here is my local run output: 3 6 1 1 1 2 2 3 -------- 280716864.00% 280716832.00% 280716832.00% -------- Looks like output is broken, it's visible. Have you tried to run program locally before crying in chat? Why not? 3) Why "candidates" is raw pointer? You should use vector/shared_ptr/scoped_ptr<int[]>. Or at least release array manually. Edited by author 01.03.2016 10:42 Re: Test 1 The problem was uninitialized candidates array. It worked perfectly on my local machine as the compiler I used initialized it to 0 automatically. Thanks. |
|
|