ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1263. Elections

Test 1
Posted by Arpit Jain 29 Feb 2016 09:29
Can anybody give me the test case 1?
Re: Test 1
Posted by ToadMonster 29 Feb 2016 17:48
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
Posted by Arpit Jain 1 Mar 2016 09:17
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
Posted by ToadMonster 1 Mar 2016 10:36
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
Posted by Arpit Jain 1 Mar 2016 12:41
The problem was uninitialized candidates array. It worked perfectly on my local machine as the compiler I used initialized it to 0 automatically. Thanks.