我刚刚制作了一个需要在足球比赛中找到最少量观众的功能。它适用于所有价值但只有一个,团队[10] 似乎它指向内存中的随机位置,我似乎无法找到原因。这似乎是随机的。
Output:
FCN, 37.250000
SDR, 40.408000
FCM, 66.279000
VFF, 42.273000
OB, 65.967000
HOB, 22.352000
AGF, 75.126000
BIF, 124.341000
AAB, 66.410000
EFB, 53.708000
FCK, 128.433000 // This value changes randomly for each time i compile
RFC, 48.314000
Team: HOB, Spectators:22.352000
void solve_task_four(ROUND *round, TEAM *team) {
int j = 0;
int i = 0;
int k = 0;
for(i=0; i<33; i++) {
for(j=0; j<6; j++) {
if(round[i].match[j].year == 2015) {
for(k=0; k<12; k++) {
if(strcmp(round[i].match[j].home_team,team[k].name)==0) {
team[k].spectators_home_last_year += round[i].match[j].spectators;
}
}
}
}
}
for(k=0; k<12; k++) {
printf("%s, %lf\n", team[k].name, team[k].spectators_home_last_year);
}
}
我有一个叫做圆形的比赛结构。结构匹配,其中存储有关每个匹配的数据。然后我有一个结构团队。我已经组建了一系列球队,我在那里存储有关球队观众数量和名字的数据。
编辑:它实际上打印了正确值的一半。其他一半打印例如:
FCK, 11619132426987445786417210392049029283197879336796768202803907011075546173646479715331152202283963354268608554533948573765823213199739004181127023348833923632578496785562152249963391728687857881966870769941957750816768.000000
编辑: 结构:
typedef struct {
char *name;
int points, matches_played,
matches_won, matches_draw, matches_lost,
matches_won_home, matches_won_away,
goals_for, goals_against, goal_difference;
double spectators_home_last_year;
} TEAM;
填充结构 - 一组团队。 (团队数量为12人)
TEAM team[NUMBER_OF_TEAMS];