MuffinMonster

Class Task 49#

Feb 18th, 2014
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.46 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8.     class Program
  9.     {
  10.         static void Vote(int num, int[,] arr)
  11.         {
  12.             for (int i = 0; i < arr.GetLength(i); i++)
  13.             {
  14.                 Console.Write("Kid " + (num + 1) + "# enter your vote for disk " + (i + 1) + "#:");
  15.                 arr[num, i] = int.Parse(Console.ReadLine());
  16.             }
  17.         }
  18.         static int MostSold(int[,] disk)
  19.         {
  20.             int max = int.MinValue;
  21.             int counter = 0;
  22.             int location;
  23.             int most;
  24.             for (int j = 0; j < disk.GetLength(1); j++)
  25.             {
  26.                 for (int i = 0; i < disk.GetLength(0); i++)
  27.                 {
  28.                     location = i;
  29.                     if (disk[i, j] == 1)
  30.                     {
  31.                         counter++;
  32.                     }
  33.                 }
  34.                 max = Math.Max(counter, max);
  35.                 if (counter == max)
  36.                     most = location;
  37.             }
  38.             return most;
  39.         }
  40.         static int Alldisks(int[,] arr)
  41.         {
  42.             bool ok = true;
  43.             int counter = 0;
  44.             for (int i = 0; i < arr.GetLength(0); i++)
  45.             {
  46.                 for (int j = 0; j < arr.GetLength(1); i++)
  47.                 {
  48.                     if (arr[i, j] != 1)
  49.                         ok = false;
  50.                 }
  51.                 if (ok == true)
  52.                     counter++;
  53.                 ok = true;
  54.             }
  55.             return counter;
  56.         }
  57.         static double AvgDisks(int[,] arr)
  58.         {
  59.             int counter = 0;
  60.             for (int i = 0; i < arr.GetLength(0); i++)
  61.             {
  62.                 for (int j = 0; j < arr.GetLength(1); j++)
  63.                 {
  64.                     if (arr[i, j] == 1)
  65.                         counter++;
  66.                 }
  67.             }
  68.             return ((double)counter / arr.GetLength(0));
  69.         }
  70.         static void Main(string[] args)
  71.         {
  72.             Console.Write("Amount of kids: ");
  73.             int n = int.Parse(Console.ReadLine());
  74.             int[,]disk = new int[n,30];
  75.             for (int i = 0; i < disk.GetLength(0); i++)
  76.             {
  77.                 Vote(i, disk);
  78.             }
  79.             int most = MostSold(disk);
  80.             int alldisks = Alldisks(disk);
  81.             double avg = AvgDisks(disk);
  82.         }
  83.     }
  84. }
Add Comment
Please, Sign In to add comment