Results 1 to 11 of 11

Thread: Soccer tournament, partitioning games

Threaded View

  1. #5
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    Code:
    //This program is trying to solve soccer team combination problem for troplosti
    //for 5 teams per group
    #include <iostream.h>
    #include <stdlib.h>
    #include <stdio.h>
    //Number of combinations for 5 teams= 5*4/2 = 10
    
    void checkrepeat();
    
    
    char array[5]={'A','B','C','D','E'};
    int endnum=0;
    char comb[10][5];
    
    int main()
    {
    
          for(int cnt=0;cnt<5;++cnt)
          {
              sprintf(comb[endnum],"%c %c",array[0],array[1]);
              printf("%s\n", comb[endnum]);
              ++endnum;
              
              char swap=array[0];
              array[0]=array[1];
              array[1]=array[2];
              array[2]=array[3];
              array[3]=array[4];
              array[4]=swap;
          }
          for(int cnt=0;cnt<3;++cnt)
          {
              sprintf(comb[endnum],"%c %c",array[cnt],array[cnt+2]);
              printf("%s\n", comb[endnum]);
              ++endnum;
          }
          for(int cnt=0;cnt<2;++cnt)
          {
              sprintf(comb[endnum],"%c %c",array[cnt],array[cnt+3]);
              printf("%s\n", comb[endnum]);
              ++endnum;
          
          }
          checkrepeat();
          system("PAUSE");
          
          return 0;
    }
    //=====================================================
    //function for checking combination doesn't repeat itself.
    void checkrepeat()
    {
        for(int cnt=0;cnt<10;++cnt)
        {
            for(int cnt1=0;cnt1<10;++cnt1)
            {
                if(cnt==cnt1) continue;
                if(strcmp(comb[cnt],comb[cnt1])== 0) 
                    printf("Error at %d & %d",cnt, cnt1);
            }
        }
    
    
    }
    Here's the output,
    =============
    A B
    B C
    C D
    D E
    E A
    A C
    B D
    C E
    A D
    B E
    Last edited by transcendental; Jul 26th, 2002 at 04:55 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width