Advertisement
Guest User

szveg

a guest
Jan 18th, 2014
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.09 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 Feltolt(int[,] t, Random r)
  11.         {
  12.           /*  for (int i = 0; i < 5; i++)
  13.             {
  14.                 for (int j = 0; j < 10; j++)
  15.                 {
  16.                     t[i, j] = r.Next(10, 100);
  17.                 }
  18.             } */
  19.             t[0, 0] = r.Next(10, 100);
  20.             int x = 0;
  21.             int y = 1;
  22.  
  23.             while (x < 5)
  24.             {
  25.                 int n=r.Next(10,100);
  26.                 if (!Vane(t, n, x, y))
  27.                 {
  28.                     t[x, y] = n;
  29.                     y++;
  30.                     if (y == 10)
  31.                     {
  32.                         y = 0;
  33.                         x++;
  34.                     }
  35.                 }
  36.             }
  37.         }
  38.         static bool Vane(int[,] t, int k,int x, int y)
  39.         {
  40.             int i = 0;
  41.             int j = 0;
  42.             bool keres = true;
  43.             bool talal= false;
  44.             while (keres)
  45.             {
  46.                 if (k == t[i, j])
  47.                 {
  48.                     keres = false;
  49.                     talal = true;
  50.                 }
  51.                 else
  52.                 {
  53.                     j++;
  54.                     if (j == 10)
  55.                     {
  56.                         j = 0;
  57.                         i++;
  58.                     }
  59.                     if ((i == x) && (j == y))
  60.                     {
  61.                         keres = false;
  62.                        
  63.                     }
  64.                 }
  65.             }
  66.             return talal;
  67.         }
  68.         static void Kiir(int[,] t, bool l)
  69.         {
  70.             for (int i = 0; i < 5; i++)
  71.             {
  72.                 for (int j = 0; j < 10; j++)
  73.                 {
  74.                     Console.Write("{0,3}", t[i, j]);
  75.                 }
  76.                     if (l)
  77.                     {
  78.                         Console.Write(" | {0}. sor  Min: {1}  Max:{2}  Avg:{3}", i + 1, Min(t, i), Max(t, i), Avg(t, i));
  79.                     }
  80.                     Console.WriteLine();
  81.                
  82.                
  83.             }
  84.             Console.WriteLine();
  85.         }
  86.         static int Min(int[,] t, int sor)
  87.         {
  88.             int min =0;
  89.             for (int j = 1; j < 10; j++)
  90.             {
  91.                 if (t[sor, min] > t[sor, j])
  92.                 {
  93.                     min = j;
  94.                 }
  95.             }
  96.             return t[sor, min];
  97.         }
  98.         static int Max(int[,] t, int sor)
  99.         {
  100.             int max = 0;
  101.             for (int j = 1; j < 10; j++)
  102.             {
  103.                 if (t[sor, max] < t[sor, j])
  104.                 {
  105.                     max = j;
  106.                 }
  107.             }
  108.             return t[sor, max];
  109.         }
  110.         static double Avg(int[,] t, int sor)
  111.         {
  112.             int sum = 0;
  113.             for (int j = 0; j < 10; j++)
  114.             {
  115.                 sum += t[sor, j];
  116.             }
  117.             return (double) sum / 10;
  118.         }
  119.         static void Rendez(int[,] t)
  120.         {
  121.             for (int i = 0; i < 5; i++)
  122.             {
  123.                 for (int x = 0; x < 10 - 1; x++)
  124.                 {
  125.                     int min = x;
  126.                     for (int y = x + 1; y < 10; y++)
  127.                     {
  128.                         if (t[i, min] > t[i, y])
  129.                         {
  130.                             min = y;
  131.                         }
  132.                     }
  133.                         if (min != x)
  134.                         {
  135.                             int temp = t[i, min];
  136.                             t[i, min] = t[i, x];
  137.                             t[i, x] = temp;
  138.                         }
  139.                     }
  140.                
  141.             }
  142.         }
  143.         static void Main(string[] args)
  144.         {
  145.             int[,] t = new int[5, 10];
  146.             Random r = new Random();
  147.             Feltolt(t, r);
  148.             Kiir(t,true);
  149.             Rendez(t);
  150.             Kiir(t,false);
  151.             Console.ReadKey();
  152.         }
  153.     }
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement