Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
cup tournament prediction
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { /* Consider a cup tournament system of n entry teams. Winning team proceeds to the next round until the last team stands, the tournament winner. Consider an array of zeros and ones whereas zeros are considered as the left team win in a match and ones are considered as the right team win. Create a function calculateScore(a, p) with two arrays of zeros and ones where first array holds actual scores of the matches in a tournament and second array holds predicted scores of the matches of that tournament. Score count is incremented when the match result from the actual and predicted array match. Note: Not all matches of result in actual and predicted scores array are always the real match (left team win can be different team in two arrays if it is not the same team from the previous round) */ public static void Main(string[] args) { int[] a = {0,1,0,1,1,0,1}; int[] p = {0,1,1,0,1,0,1}; Console.WriteLine(calculateScore(a,p)); } public static int calculateScore(int[] a, int[] p) { //all checks like equal array size and array size to be (2 to the power of n) - 1 int teams = (a.Length + 1); int score = 0; int[] actual = new int[a.Length]; int[] predict = new int[a.Length]; for (int i = 0; i < a.Length; i++) { if(i < teams/2) { actual[i] = i * 2 + 1 + a[i]; predict[i] = i * 2 + 1 + p[i]; } else { actual[i] = actual[2*i - teams + a[i]]; predict[i] = predict[2*i - teams + p[i]]; } score += actual[i] == predict[i] ? 1 : 0; } Console.WriteLine(string.Join(",", actual)); Console.WriteLine(string.Join(",", predict)); return score; } } }
run
|
edit
|
history
|
help
0
Fibonacci series
first test
Deadlock Example
Basic
1.1 Basics: language constructs
vcdgdfgdfdfd
select z kolekcji w kolekcji (np. dokumenty i pizycje)
sdfghjkilujyht
Write a program to count the occurrence of each distinct item in the array?
megha