Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

help on round robin tournament

35 views
Skip to first unread message

mattia

unread,
Nov 6, 2009, 9:03:06 PM11/6/09
to
I want to create a round robin tournament. The function receive a list
(I've used a deque) and for now just prints to stdout the results (e.g.
the round number and the schedule). If I wanted to provide the user a
data structure that has all the miningful informations, what do you
propose?

Here my code (I'm a C++ novice):

#include <iostream>
#include <deque>

int main(void)
{
// games per team: n - 1
std::deque<int> tournament;
int c;
int first = 0;
// simple example with integers
for (int i = 1; i < 8; i++)
{
tournament.push_back(i);
}
bool even = !(tournament.size() & 1);
if (even)
{
first = tournament.front();
tournament.pop_front();
}
for (int j = 0; j < tournament.size() - 1; j++)
{
std::cout << "Round " << j + 1 << ":" << std::endl;
if (even)
{
std::cout << first << " vs " << tournament.back() <<
std::endl;
}
for (int i = 0; i < tournament.size()/2; i++)
{
std::cout << tournament[i] << " vs " << tournament
[tournament.size() - i - 2] << std::endl;
}
tournament.push_front(tournament.back());
tournament.pop_back();
}
c = getchar();
return 0;
}

Thanks, Mattia

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

red floyd

unread,
Nov 7, 2009, 7:24:03 PM11/7/09
to
mattia wrote:
> I want to create a round robin tournament. The function receive a list
> (I've used a deque) and for now just prints to stdout the results (e.g.
> the round number and the schedule). If I wanted to provide the user a
> data structure that has all the miningful informations, what do you
> propose?
>
> [redacted]

http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.2

mattia

unread,
Nov 8, 2009, 10:52:58 AM11/8/09
to
Il Sat, 07 Nov 2009 18:24:03 -0600, red floyd ha scritto:

> mattia wrote:
>> I want to create a round robin tournament. The function receive a list
>> (I've used a deque) and for now just prints to stdout the results (e.g.
>> the round number and the schedule). If I wanted to provide the user a
>> data structure that has all the miningful informations, what do you
>> propose?
>>
>> [redacted]
>
> http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.2

Well, I'm sorry you've misunderstood but I was asking for an advice, not
for homework (that I don't have since a long time ago). I've also said
that I'm a c++ novice, so I wated to know more about the OO programming
facing a simple problem that I was trying to solve.

red floyd

unread,
Nov 8, 2009, 5:29:38 PM11/8/09
to
mattia wrote:
> Il Sat, 07 Nov 2009 18:24:03 -0600, red floyd ha scritto:
>
>> mattia wrote:
>>> I want to create a round robin tournament. The function receive a list
>>> (I've used a deque) and for now just prints to stdout the results (e.g.
>>> the round number and the schedule). If I wanted to provide the user a
>>> data structure that has all the miningful informations, what do you
>>> propose?
>>>
>>> [redacted]
>> http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.2
>
> Well, I'm sorry you've misunderstood but I was asking for an advice, not
> for homework (that I don't have since a long time ago). I've also said
> that I'm a c++ novice, so I wated to know more about the OO programming
> facing a simple problem that I was trying to solve.
>

Sorry. Then you're better off asking in comp.algorithms. There's
nothing C++ specific in your question, other than your use of a deque.

mattia

unread,
Nov 8, 2009, 9:28:14 PM11/8/09
to
Il Sun, 08 Nov 2009 16:29:38 -0600, red floyd ha scritto:

> mattia wrote:
>> Il Sat, 07 Nov 2009 18:24:03 -0600, red floyd ha scritto:
>>
>>> mattia wrote:
>>>> I want to create a round robin tournament. The function receive a
>>>> list (I've used a deque) and for now just prints to stdout the
>>>> results (e.g. the round number and the schedule). If I wanted to
>>>> provide the user a data structure that has all the miningful
>>>> informations, what do you propose?
>>>>
>>>> [redacted]
>>> http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.2
>>
>> Well, I'm sorry you've misunderstood but I was asking for an advice,
>> not for homework (that I don't have since a long time ago). I've also
>> said that I'm a c++ novice, so I wated to know more about the OO
>> programming facing a simple problem that I was trying to solve.
>>
>>
> Sorry. Then you're better off asking in comp.algorithms. There's
> nothing C++ specific in your question, other than your use of a deque.

Well, I know no comp.algorithms newsgroup...

0 new messages