C#投票模拟器(如何计算零或未投票项目/国家)

C#投票模拟器(如何计算零或未投票项目/国家),c#,arrays,struct,voting,C#,Arrays,Struct,Voting,我正在使用欧洲电视台的投票比赛模拟器 26个国家必须随机投票给其他10个国家(没有重复投票,本身也没有重复投票) 所以我对(Countries.Length)和(PossibleVotes.Length)分别做了a和a 分配选票 甚至在投票最高(12分)的柜台上展示“最好”的赢家 这项工作已经完成 守则: //struct array country[26] //country[].sName = Spain, Italy, France... //country.iVotes = Total

我正在使用欧洲电视台的投票比赛模拟器

26个国家必须随机投票给其他10个国家(没有重复投票,本身也没有重复投票)

所以我对(Countries.Length)和(PossibleVotes.Length)分别做了a和a 分配选票

甚至在投票最高(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'
//结构数组国家/地区[26]
//国家[]。sName=西班牙、意大利、法国。。。
//country.iVotes=总票数
//country.iTwelves=接收总数为12的计数器
//country.iZeros=接收总数为0的计数器
//I允许投票[10]{12,10,8,7,6,5,4,3,2,1}
for(int i=0;i
老师还要求显示“较低”的获胜者,即投票较少或投票为“0”的国家(或平局中的国家)

我的想法是在我将真正可能的选票分配给10个随机国家后,再将“0”票分配给其他16个国家

我还对伪代码的抽象想法或评论感兴趣,想一想


谢谢

< P>而不是保持每个国家的选票和零点的数目(如IvOpts,IsRees,ITS)考虑这个方法。< /P> 每个国家保留所有选票。例如,如果有10轮投票,那么您可以有一个由10个元素组成的数组,每个元素持有该轮投票的分数,例如12、10、8等,默认值为0

然后你有一个分为三部分的程序

  • 记录所有投票

  • 将每个国家的票数相加 并找到最高的一个,考虑到领带

  • 将每个国家的票数相加,找出最低票数, 同样,考虑到关系

  • 第2部分和第3部分可以在1个循环中,如果您愿意的话,但不希望如此