【发布时间】:2021-05-06 14:28:17
【问题描述】:
我正在使用 Eurovision 投票竞赛模拟器。
26 个国家必须随机投票给其他 10 个国家(不重复也不自己)。
所以我做了一个 for (Countries.Length) 和一个 for (PossibleVotes.Length) 用于分配选票。
甚至处理投票最高(12 分)的计数器以显示“最佳”获胜者。
这已经完成了。
代码:
//struct array country[26]
//country[].sName = Spain, Italy, France...
//country.iVotes = Total votes
//country.iTwelves = Counter for total12 recieved
//country.iZeros = Counter for total 0 recieved
// iPossibleVotes[10] {12 , 10 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 }
for (int i = 0 ; i < country.Length ; i++){
Console.WriteLine("\n___Country " + (i+1) + " " + country[i].sName + "___");
Console.WriteLine("\nVotes:");
int[] iVotedCountry = Utils.RandomArrayWitoutDuplicates(i);
//Function to make an array of 10 random integers without duplicates nor itself (i value)
//Executes 10 times
for (int j = 0 ; j < iVotedCountry.Length ; j++){
Console.WriteLine("-" + country[iVotedCountry[j]].sName + " with " + iPossibleVotes[j] + " points. ");
//If j = 0 equals to iPossibleVotes[] =12, sum iTwelves counter
if (j == 0){
country[iVotedCountry[j]].iTwelves++;
}
} // END FOR (iVotedCountry.Length) Countries that are being voted.
for (int k = 0 ; k < country.Length ; k++){
if (k != iVotedCountry[j]) {
country[k].iZeros++;
}
}
} //END COUNTRY.Length ARRAY
//Expected output
Console.WriteLine("___TheLooser___\nThe country or countries with more zeros recieved are: " );
//Then sort them in an array
//BUT I can't handle to count the times a country hasn't been voted or voted '0'
教师还要求展示“TheLooser”获胜者,即投票较少或投票为“0”的国家(或平局的国家)。
我的想法是在我将实际的 PossibleVotes 分配给 10 个随机国家之后,将“0”票分配给其他 16 个国家。
我也对伪代码抽象思想或cmets感兴趣,可以考虑一下。
谢谢
【问题讨论】: