ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1263. Выборы

Test 1
Послано Arpit Jain 29 фев 2016 09:29
Can anybody give me the test case 1?
Re: Test 1
Послано ToadMonster 29 фев 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
Послано Arpit Jain 1 мар 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
Послано ToadMonster 1 мар 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
Послано Arpit Jain 1 мар 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.