Ytuoj-World Cup Group competition

Source: Internet
Author: User

DescriptionNote: This topic is free to design, but you must use classes for code design.

The World Cup 32 teams are divided into eight teams, each team has four teams to play, each team must play with the other three teams and only one game, each group of 4 team cycle competition, a total of 6 games (A1-A2;A1-A3;A1-A4;A2-A3;A2-A4;A3-A4), Each match 90 minutes, wins the flat negative respectively to accumulate 3, 1, 0 points. The top two teams of each group points into the knockout stage of the 1/8 finals, a total of 16 detachment, namely "16 strong".

Each team has four teams, and their rankings are determined according to the following rules:
A, high points ranked top
b, the group's total net wins the ball high ranked top
C, the group's total number of goals high ranked top
D, not sure
The net winning number is the difference between the number of goals scored (positive) and the number of missed balls (positive numbers).
For example, red team wins yellow team 4:2, blue team wins yellow team 3:1, Red Team negative Blue Team 2:3
Red Team scored 6 goals, lost 5 goals, net winning ball number: 6-5=1
Yellow team scored 3 goals, lost 7 goals, net winning ball number: 3-7=-4
Blue Team scored 6 goals, lost 3 goals, net winning ball number: 6-3=3
//Below is a reference code
#include <stdio.h>
#include <iostream>
#include <string>
using namespace Std;

Class Footballgroup
{
Private
int score[4]; Total points
int goaldiff[4]; Total net Win Ball
int totalgoals[4]; Total number of goals scored
String teamname[4]; The name of the team
Public
Footballgroup ()
{
for (int i=0; i<4; i++)
{
score[i]=goaldiff[i]=totalgoals[i]=0;
}
}
void setteamname (int teamindex,string name)//Set TEAMINDEX+1 team name
{
Teamname[teamindex] = name;
}
void Addmatchresult (int teamindex1,int teamindex2,int score1,int score2);
void Showresult ();
};
int main ()
{
Footballgroup Groupa;
String name;
int i,j;
for (i=0; i<4; i++)
{
cin>>name;
Groupa.setteamname (I,name); Name of the team A1,A2,A3,A4
}
int score1,score2;
for (i=0; i<3; i++)//a1-a2;a1-a3;a1-a4;a2-a3;a2-a4;a3-a4
for (j=i+1; j<4; j + +)
{
cin>>score1>>score2; The score of the two teams
Groupa.addmatchresult (I,j,score1,score2);
}
Groupa.showresult ();
return 0;
}

Input

Name of the first row of 4 teams
The second line starts to line seventh, the score of 6 games (A1-A2;A1-A3;A1-A4;A2-A3;A2-A4;A3-A4)

Output

Two teams entering the knockout stage, if unsure, output "NO"

Sample Input
A1 A2 A3 A41 20 02 33 12 21 2
Sample Output
A2 A4
HINT

The code is as follows:

#include <stdio.h> #include <iostream> #include <cstring>using namespace Std;class footballgroup{ Private:int Score[4]; Total integral int goaldiff[4]; Total net winning ball int totalgoals[4]; Total goals scored string teamname[4]; Team Name Public:footballgroup () {for (int i=0; i<4; i++) {Score[i]=goaldiff[i]=totalgoal        s[i]=0;    }} void Setteamname (int teamindex,string name)//Set Teamindex+1 team name {Teamname[teamindex] = name;    } void Addmatchresult (int teamindex1,int teamindex2,int score1,int score2); void Showresult ();};        void Footballgroup::addmatchresult (int teamindex1,int teamindex2,int score1,int score2) {if (Score1>score2) {        score[teamindex1]+=3;        Goaldiff[teamindex1]+=score1-score2;        Goaldiff[teamindex2]+=score2-score1;        Totalgoals[teamindex1]+=score1;    Totalgoals[teamindex2]+=score2;        } else if (score1<score2) {score[teamindex2]+=3; Goaldiff[teamindex1]+=score1-score2;        Goaldiff[teamindex2]+=score2-score1;        Totalgoals[teamindex1]+=score1;    Totalgoals[teamindex2]+=score2;        } else {score[teamindex1]+=1;        Totalgoals[teamindex1]+=score1;        Score[teamindex2]+=1;    Totalgoals[teamindex2]+=score2;    }}void Footballgroup::showresult () {int i,j,t1,t2,t3;    string C;                For (i=0, i<3; i++) for (j=i+1; j<4; J + +) {if (Score[j]>score[i]) {                T1=score[i];                SCORE[I]=SCORE[J];                SCORE[J]=T1;                T2=goaldiff[i];                GOALDIFF[I]=GOALDIFF[J];                Goaldiff[j]=t2;                T3=totalgoals[i];                TOTALGOALS[I]=TOTALGOALS[J];                TOTALGOALS[J]=T3;                C=teamname[i];                TEAMNAME[I]=TEAMNAME[J];            Teamname[j]=c;    }} if (Score[1]!=score[2]) cout<<teamname[0]<< "" <<teamname[1]<<endl; ELSE if (Score[0]!=score[1]&&score[1]==score[2]&&score[2]!=score[3]) {for (i=1; i<2; i++)                    for (j=i+1; j<3; J + +) {if (Goaldiff[j]>goaldiff[i]) {                    T1=score[i];                    SCORE[I]=SCORE[J];                    SCORE[J]=T1;                    T2=goaldiff[i];                    GOALDIFF[I]=GOALDIFF[J];                    Goaldiff[j]=t2;                    T3=totalgoals[i];                    TOTALGOALS[I]=TOTALGOALS[J];                    TOTALGOALS[J]=T3;                    C=teamname[i];                    TEAMNAME[I]=TEAMNAME[J];                Teamname[j]=c; }} if (Goaldiff[1]!=goaldiff[2]) {cout<<teamname[0]<< "" <<teamname        [1]<<endl; } else {if (totalgoals[1]>totalgoals[2]) cout<<teamname[0]<< "" &lt         ;<teamname[1]<<endl;   else if (totalgoals[1]<totalgoals[2]) cout<<teamname[0]<< "" <<teamname[2]<<end            L        else cout<< "NO" <<endl; }} else if (Score[0]!=score[1]&&score[1]==score[2]&&score[2]==score[3]) {for (i=1; i<3 ;                    i++) for (j=i+1; j<4; J + +) {if (Goaldiff[j]>goaldiff[i]) {                    T1=score[i];                    SCORE[I]=SCORE[J];                    SCORE[J]=T1;                    T2=goaldiff[i];                    GOALDIFF[I]=GOALDIFF[J];                    Goaldiff[j]=t2;                    T3=totalgoals[i];                    TOTALGOALS[I]=TOTALGOALS[J];                    TOTALGOALS[J]=T3;                    C=teamname[i];                    TEAMNAME[I]=TEAMNAME[J];                Teamname[j]=c; }} if (Goaldiff[1]!=goaldiff[2]) {cout<<teamname[0]<<"        "<<teamname[1]<<endl; } else if (Goaldiff[1]==goaldiff[2]&&goaldiff[2]!=goaldiff[3]) {if (Totalgoals[1]>tot            ALGOALS[2]) cout<<teamname[0]<< "" <<teamname[1]<<endl;            else if (totalgoals[1]<totalgoals[2]) cout<<teamname[0]<< "" <<teamname[2]<<endl;        else cout<< "NO" <<endl;                } else if (Goaldiff[1]==goaldiff[2]&&goaldiff[2]==goaldiff[3]) {for (i=1; i<3; i++)                    for (j=i+1; j<4; J + +) {if (Totalgoals[j]>totalgoals[i])                        {T1=score[i];                        SCORE[I]=SCORE[J];                        SCORE[J]=T1;                        T2=goaldiff[i];                        GOALDIFF[I]=GOALDIFF[J];                        Goaldiff[j]=t2;         T3=totalgoals[i];               TOTALGOALS[I]=TOTALGOALS[J];                        TOTALGOALS[J]=T3;                        C=teamname[i];                        TEAMNAME[I]=TEAMNAME[J];                    Teamname[j]=c; }} if (Totalgoals[1]!=totalgoals[2]) cout<<teamname[0]<< "" <<            teamname[1]<<endl;        else cout<< "NO" <<endl;  }} else if (Score[1]==score[2]&&score[0]==score[1]&&score[2]==score[3]) {for (i=0; i<3;                    i++) for (j=i+1; j<4; J + +) {if (Goaldiff[j]>goaldiff[i]) {                    T1=score[i];                    SCORE[I]=SCORE[J];                    SCORE[J]=T1;                    T2=goaldiff[i];                    GOALDIFF[I]=GOALDIFF[J];                    Goaldiff[j]=t2;                    T3=totalgoals[i];                  TOTALGOALS[I]=TOTALGOALS[J];  TOTALGOALS[J]=T3;                    C=teamname[i];                    TEAMNAME[I]=TEAMNAME[J];                Teamname[j]=c; }} if (Goaldiff[1]!=goaldiff[2]) {cout<<teamname[0]<< "" <<teamname[        1]<<endl;            } else if (Goaldiff[0]!=goaldiff[1]&&goaldiff[1]==goaldiff[2]&&goaldiff[2]!=goaldiff[3]) { if (totalgoals[1]>totalgoals[2]) cout<<teamname[0]<< "" <<teamname[1]<<            Endl            else if (totalgoals[1]<totalgoals[2]) cout<<teamname[0]<< "" <<teamname[2]<<endl;        else cout<< "NO" <<endl;            } else if (Goaldiff[0]!=goaldiff[1]&&goaldiff[1]==goaldiff[2]&&goaldiff[2]==goaldiff[3]) { For (I=1, i<3; i++) for (j=i+1; j<4; J + +) {if (totalgoals[j ]>totalgoaLs[i]) {t1=score[i];                        SCORE[I]=SCORE[J];                        SCORE[J]=T1;                        T2=goaldiff[i];                        GOALDIFF[I]=GOALDIFF[J];                        Goaldiff[j]=t2;                        T3=totalgoals[i];                        TOTALGOALS[I]=TOTALGOALS[J];                        TOTALGOALS[J]=T3;                        C=teamname[i];                        TEAMNAME[I]=TEAMNAME[J];                    Teamname[j]=c; }} if (Totalgoals[1]!=totalgoals[2]) cout<<teamname[0]<< "" <<t            eamname[1]<<endl;        else cout<< "NO" <<endl;            } else if (Goaldiff[0]==goaldiff[1]&&goaldiff[1]==goaldiff[2]&&goaldiff[2]!=goaldiff[3]) { For (i=0, i<2; i++) for (j=i+1; j<3; J + +) {if (totalgoals[J]>totalgoals[i]) {t1=score[i];                        SCORE[I]=SCORE[J];                        SCORE[J]=T1;                        T2=goaldiff[i];                        GOALDIFF[I]=GOALDIFF[J];                        Goaldiff[j]=t2;                        T3=totalgoals[i];                        TOTALGOALS[I]=TOTALGOALS[J];                        TOTALGOALS[J]=T3;                        C=teamname[i];                        TEAMNAME[I]=TEAMNAME[J];                    Teamname[j]=c; }} if (Totalgoals[0]!=totalgoals[1]&&totalgoals[1]!=totalgoals[2]) COUT&L            t;<teamname[0]<< "" <<teamname[1]<<endl;        else cout<< "NO" <<endl;            } else if (Goaldiff[0]==goaldiff[1]&&goaldiff[1]==goaldiff[2]&&goaldiff[2]==goaldiff[3]) { For (i=0, i<3; i++) for (j=i+1; j<4; j++) {if (Totalgoals[j]>totalgoals[i]) {t1=s                        Core[i];                        SCORE[I]=SCORE[J];                        SCORE[J]=T1;                        T2=goaldiff[i];                        GOALDIFF[I]=GOALDIFF[J];                        Goaldiff[j]=t2;                        T3=totalgoals[i];                        TOTALGOALS[I]=TOTALGOALS[J];                        TOTALGOALS[J]=T3;                        C=teamname[i];                        TEAMNAME[I]=TEAMNAME[J];                    Teamname[j]=c; }} if (Totalgoals[1]!=totalgoals[2]) cout<<teamname[0]<< "" <<te            amname[1]<<endl;        else cout<< "NO" <<endl;    }}}int Main () {Footballgroup groupa;    String name;    int i,j;        for (i=0; i<4; i++) {cin>>name; Groupa.setteamname (I,name); Team A1,a2,a3,aName of 4} int score1,score2; For (i=0, i<3; i++)//a1-a2;a1-a3;a1-a4;a2-a3;a2-a4;a3-a4 for (j=i+1; j<4; J + +) {cin>> score1>>score2;        The scores of the two teams groupa.addmatchresult (I,J,SCORE1,SCORE2);    } groupa.showresult (); return 0;}

Operation Result:



Learning experience:

For a long time not in the brush problem so excited,,, this problem analysis,,, can really hard,, time one hours after all to do out, heard is the last 13 session of the exam, then only a few people did come out haha ~


The topic code is a bit verbose,, is a step by step analysis, there may be an optimization method, but I do not want to think about, there is a place can be corrected, all the comparison of the exchange into a function, in fact, the beginning of the same time, but there was a mistake, only exchanged the value and name of the comparison, The other two were not exchanged, so they were wrong. You can add a function sort in class, but then swap all the data members in class and have the intention to modify it yourself, I will not modify it here, and then I submit it.


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Ytuoj-World Cup Group competition

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.