Advertisement
AvengersAssemble

Shield

Apr 30th, 2014
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace BangbuttExc
  8. {
  9.     class Program
  10.     {
  11.         //Question 2
  12.         public static int[] BigArr(int[,] a)
  13.         {
  14.             int[] b = new int[5];
  15.             int sum, count = 0;
  16.             for (int i = 0; i < a.GetLength(0); i++)
  17.             {
  18.                 sum = 0;
  19.                 for (int k = 0; k < a.GetLength(1); k++)
  20.                     sum += a[i, k];
  21.                 if (sum > 100)
  22.                 {
  23.                     b[count] = i;
  24.                     count++;
  25.                 }
  26.             }
  27.                 return b;
  28.         }
  29.  
  30.  
  31.         //Question 3
  32.         public static void SolveQ2()
  33.         {
  34.             int num, count = 0;
  35.             for(int i = 1; i < 26; i++)
  36.             {
  37.                 num = int.Parse(Console.ReadLine());
  38.                 if (Math.Abs(num - i) <= 2)
  39.                     count++;
  40.             }
  41.             Console.WriteLine(count);
  42.         }
  43.  
  44.  
  45.         //Question 5
  46.         public static bool ContainsChars(string st1, string st2)
  47.         {
  48.             bool flag;
  49.             for (int i = 0; i < st1.Length; i++)
  50.             {
  51.                 flag = false;
  52.                 for (int m = 0; m < st2.Length; m++)
  53.                     if (st2[m] == st1[i])
  54.                         flag = true;
  55.                 if (!flag)
  56.                     return false;
  57.             }
  58.                 return true;
  59.         }
  60.  
  61.  
  62.         //Question 7a
  63.         public static char CharStuff(string st1, string st2)
  64.         {
  65.             if (st1.Length > st2.Length)
  66.             {
  67.                 if (st1.Length == 2 * st2.Length)
  68.                     return st2[st2.Length - 1];
  69.                 return st1[st1.Length - 1];
  70.             }
  71.             else
  72.             {
  73.                 if(st2.Length == 2 * st1.Length)
  74.                     return st1[st1.Length - 1];
  75.                 return st2[st2.Length - 1];
  76.             }
  77.         }
  78.         //Question 7b
  79.         public static void SolveQ7()
  80.         {
  81.             string output = "", st1, st2;
  82.             for (int i = 0; i < 4; i++)
  83.             {
  84.                 st1 = Console.ReadLine();
  85.                 st2 = Console.ReadLine();
  86.                 output += CharStuff(st1, st2);
  87.             }
  88.             Console.WriteLine(output);
  89.         }
  90.  
  91.  
  92.         //Question 8a
  93.         public static int GetMonth(string st)
  94.         {
  95.             return int.Parse(st.Substring(3, 2));
  96.         }
  97.         //Question 8b
  98.         public static void SolveQ8()
  99.         {
  100.             int count1 = 0, count2 = 0, count3 = 0, count4 = 0;
  101.             string st;
  102.             st = Console.ReadLine();
  103.             while (st != "00/00/0000")
  104.             {
  105.                 switch (GetMonth(st))
  106.                 {
  107.                     case 9:
  108.                     case 10:
  109.                     case 11:
  110.                         count1++;
  111.                         break;
  112.                     case 12:
  113.                     case 1:
  114.                     case 2:
  115.                         count2++;
  116.                         break;
  117.                     case 3:
  118.                     case 4:
  119.                     case 5:
  120.                         count3++;
  121.                         break;
  122.                     default:
  123.                         count4++;
  124.                         break;
  125.                 }
  126.                 Console.WriteLine(GetMonth(st));
  127.                 st = Console.ReadLine();
  128.             }
  129.             Console.WriteLine("Fall - " + count1);
  130.             Console.WriteLine("Winter - " + count2);
  131.             Console.WriteLine("Spring - " + count3);
  132.             Console.WriteLine("Summer(time sadness) - " + count4);
  133.         }
  134.  
  135.  
  136.         //Question 9a
  137.         public static bool DominantCell(int[,] arr, int a, int b)
  138.         {
  139.             for (int i = 0; i < arr.GetLength(0); i++)
  140.             {
  141.                 if (arr[i, b] >= arr[a, b])
  142.                     return false;
  143.             }
  144.             for (int i = 0; i < arr.GetLength(1); i++)
  145.             {
  146.                 if (arr[a, i] >= arr[a, b])
  147.                     return false;
  148.             }
  149.             return true;
  150.         }
  151.         //Question 9b
  152.         public static bool DominantDiagonal(int[,] arr)
  153.         {
  154.             for (int i = 0; i < arr.GetLength(0); i++)
  155.             {
  156.                 if (!DominantCell(arr, i, i))
  157.                     return false;
  158.             }
  159.                 return true;
  160.         }
  161.  
  162.  
  163.         //Question 10a
  164.         public static void InitializeArray(int[,] arr)
  165.         {
  166.             int input;
  167.             input = int.Parse(Console.ReadLine());
  168.             while (input != 999)
  169.             {
  170.                 arr[input / 100 - 1, (input / 10) % 10 - 1] = input % 10;
  171.                 input = int.Parse(Console.ReadLine());
  172.             }
  173.         }
  174.         //Question 10b
  175.         public static int FrameSum(int[,] arr)
  176.         {
  177.             int sum = 0;
  178.             for (int k = 0; k < arr.GetLength(1); k += arr.GetLength(1) - 1)
  179.             {
  180.                 for (int i = 0; i < arr.GetLength(0); i++)
  181.                     sum += arr[i, k];
  182.             }
  183.             for (int k = 0; k < arr.GetLength(0); k += arr.GetLength(0) - 1)
  184.             {
  185.                 for (int i = 1; i < arr.GetLength(1) - 1; i++)
  186.                     sum += arr[k, i];
  187.             }
  188.                 return sum;
  189.         }
  190.         //Question 10c(kinda)
  191.         public static bool LegitAndShit(int[,] arr)
  192.         {
  193.             int sum = 0;
  194.             for(int i = 0; i < arr.GetLength(0); i++)
  195.                 for(int k = 0; k < arr.GetLength(1); k++)
  196.                     sum += arr[i, k];
  197.             return FrameSum(arr) > sum / 2;
  198.         }
  199.         static void Main(string[] args)
  200.         {
  201.             SolveQ2();
  202.             SolveQ8();
  203.         }
  204.     }
  205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement