Advertisement
AvengersAssemble

P65Ex15

Dec 18th, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.89 KB | None | 0 0
  1. using System;
  2.  
  3. namespace App
  4. {
  5.     class Program
  6.     {
  7.         static void Main()
  8.         {
  9.             int divison, cashier, payment = 0, max = 0, maxIndex = 0, min = int.MaxValue, currentSum, minIndex = 0, sum = 0;
  10.             int[,] shop = new int[6, 5];
  11.             for (int i = 0; i < shop.GetLength(0); i++)
  12.             {
  13.                 for (int k = 0; k < shop.GetLength(1); k++)
  14.                     shop[i, k] = 0;
  15.             }
  16.             while (payment != -1)
  17.             {
  18.                 divison = int.Parse(Console.ReadLine());
  19.                 cashier = int.Parse(Console.ReadLine());
  20.                 payment = int.Parse(Console.ReadLine());
  21.                 shop[divison, cashier] += payment;
  22.             }
  23.             for (int i = 0; i < shop.GetLength(0); i++)
  24.             {
  25.                 for (int k = 0; k < shop.GetLength(1); k++)
  26.                 {
  27.                     if (shop[i, k] > max)
  28.                     {
  29.                         maxIndex = i * 10 + k;
  30.                         max = shop[i, k];
  31.                     }
  32.                 }
  33.             }
  34.             Console.WriteLine("Divison: {0} cashier: {1}", maxIndex / 10 + 1, maxIndex % 10 + 1);
  35.             for (int i = 0; i < shop.GetLength(0); i++)
  36.             {
  37.                 currentSum = 0;
  38.                 for (int k = 0; k < shop.GetLength(1); k++)
  39.                     currentSum += shop[i, k];
  40.                 if (currentSum < min)
  41.                 {
  42.                     min = currentSum;
  43.                     minIndex = i + 1;
  44.                 }
  45.             }
  46.             Console.WriteLine("Division with minimal income: " + minIndex);
  47.             for(int i = 0; i < shop.GetLength(0); i++)
  48.             {
  49.                 for (int k = 0; k < shop.GetLength(1); k++)
  50.                     sum += shop[i, k];
  51.             }
  52.             Console.WriteLine("Total income: " + sum);
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement