Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Reset(int[,] arr)
- {
- for (int i = 0; i < arr.GetLength(0); i++)
- {
- for (int j = 0; j < arr.GetLength(1); j++)
- {
- arr[i, j] = 0;
- }
- }
- }
- static void Buy(int[,] arr)
- {
- int section, station, payment;
- Console.Write("In which section did you buy?: ");
- section = int.Parse(Console.ReadLine());
- Console.Write("In which station did you pay?: ");
- station = int.Parse(Console.ReadLine());
- Console.Write("How much did you pay?: ");
- payment = int.Parse(Console.ReadLine());
- while (payment != -1)
- {
- arr[station - 1, section - 1] += payment;
- Console.Write("In which section did you buy?: ");
- section = int.Parse(Console.ReadLine());
- Console.Write("In which station did you pay?: ");
- station = int.Parse(Console.ReadLine());
- Console.Write("How much did you pay?: ");
- payment = int.Parse(Console.ReadLine());
- }
- }
- static void Main(string[] args)
- {
- int[,] Supermarket = new int[5, 6];
- Reset(Supermarket);
- Buy(Supermarket);
- Console.Clear();
- Console.WriteLine("===================== Supermarket's info: =====================");
- for (int i = 0; i < Supermarket.GetLength(0); i++)
- {
- for (int j = 0; j < Supermarket.GetLength(1); j++)
- {
- Console.Write(Supermarket[i, j] + " ");
- }
- Console.WriteLine();
- }
- // Finding best cashier
- int max = int.MinValue;
- int station, section;
- int min = int.MaxValue;
- int counterSections = 0, counter = 0, winsection;
- for (int i = 0; i < Supermarket.GetLength(0); i++)
- {
- for (int j = 0; j < Supermarket.GetLength(1); j++)
- {
- counter += Supermarket[i, j];
- max = Math.Max(max, Supermarket[i,j]);
- if (max == Supermarket[i, j])
- {
- station = i;
- section = j;
- }
- }
- }
- for (int i = 0; i < Supermarket.GetLength(1); i++)
- {
- for (int j = 0; j < Supermarket.GetLength(0); j++)
- {
- counterSections = counterSections + Supermarket[j, i];
- min = Math.Min(min, counterSections);
- }
- min = Math.Min(min, counterSections);
- if (min == counterSections)
- {
- winsection = i;
- }
- counterSections = 0;
- }
- Console.WriteLine("Best cashier is from section " + section + "and station " + station);
- Console.WriteLine("Total earnings: " + counter + " and the section with most less earnings is " + winsection);
- Console.ReadKey();
- }
- }
- }
Add Comment
Please, Sign In to add comment