MuffinMonster

Class Task 50#

Feb 18th, 2014
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.42 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 Reset(int[,] arr)
  11.         {
  12.             for (int i = 0; i < arr.GetLength(0); i++)
  13.             {
  14.                 for (int j = 0; j < arr.GetLength(1); j++)
  15.                 {
  16.                     arr[i, j] = 0;
  17.                 }
  18.             }
  19.         }
  20.         static void Buy(int[,] arr)
  21.         {
  22.             int section, station, payment;
  23.             Console.Write("In which section did you buy?: ");
  24.             section = int.Parse(Console.ReadLine());
  25.             Console.Write("In which station did you pay?: ");
  26.             station = int.Parse(Console.ReadLine());
  27.             Console.Write("How much did you pay?: ");
  28.             payment = int.Parse(Console.ReadLine());
  29.             while (payment != -1)
  30.             {
  31.                 arr[station - 1, section - 1] += payment;
  32.                 Console.Write("In which section did you buy?: ");
  33.                 section = int.Parse(Console.ReadLine());
  34.                 Console.Write("In which station did you pay?: ");
  35.                 station = int.Parse(Console.ReadLine());
  36.                 Console.Write("How much did you pay?: ");
  37.                 payment = int.Parse(Console.ReadLine());
  38.             }
  39.         }
  40.         static void Main(string[] args)
  41.         {
  42.             int[,] Supermarket = new int[5, 6];
  43.             Reset(Supermarket);
  44.             Buy(Supermarket);
  45.             Console.Clear();
  46.             Console.WriteLine("===================== Supermarket's info: =====================");
  47.             for (int i = 0; i < Supermarket.GetLength(0); i++)
  48.             {
  49.                 for (int j = 0; j < Supermarket.GetLength(1); j++)
  50.                 {
  51.                     Console.Write(Supermarket[i, j] + " ");
  52.                 }
  53.                 Console.WriteLine();
  54.             }
  55.             // Finding best cashier
  56.             int max = int.MinValue;
  57.             int station, section;
  58.             int min = int.MaxValue;
  59.             int counterSections = 0, counter = 0, winsection;
  60.             for (int i = 0; i < Supermarket.GetLength(0); i++)
  61.             {
  62.                 for (int j = 0; j < Supermarket.GetLength(1); j++)
  63.                 {
  64.                     counter += Supermarket[i, j];
  65.                     max = Math.Max(max, Supermarket[i,j]);
  66.                     if (max == Supermarket[i, j])
  67.                     {
  68.                         station = i;
  69.                         section = j;
  70.                     }
  71.                 }
  72.             }
  73.             for (int i = 0; i < Supermarket.GetLength(1); i++)
  74.             {
  75.                 for (int j = 0; j < Supermarket.GetLength(0); j++)
  76.                 {
  77.                     counterSections = counterSections + Supermarket[j, i];
  78.                     min = Math.Min(min, counterSections);
  79.                 }
  80.                 min = Math.Min(min, counterSections);
  81.                 if (min == counterSections)
  82.                 {
  83.                     winsection = i;
  84.                 }
  85.                 counterSections = 0;
  86.             }
  87.             Console.WriteLine("Best cashier is from section " + section + "and station " + station);
  88.             Console.WriteLine("Total earnings: " + counter + " and the section with most less earnings is " + winsection);
  89.            
  90.             Console.ReadKey();
  91.         }
  92.     }
  93. }
Add Comment
Please, Sign In to add comment