Advertisement
n4wn4w

C# 4 zadachi

Apr 14th, 2015
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 30.53 KB | None | 0 0
  1. variant 1
  2.  
  3.             int sum = int.Parse(Console.ReadLine());
  4.             int diff = int.Parse(Console.ReadLine());
  5.             bool OK = false;
  6.  
  7.             string num;
  8.             for (int i = 111; i < 778; i++)
  9.             {
  10.  
  11.                 int tempSum = 0;
  12.                 int a = i;
  13.                 int b = a + diff;
  14.                 int c = b + diff;
  15.                 //string num = "";
  16.  
  17.  
  18.                 num = a.ToString() + b.ToString() + c.ToString();
  19.                 Regex r = new Regex("0|8|9");
  20.                 if (!r.IsMatch(num))  // (!num.Contains("0") && !num.Contains("8") && !num.Contains("9"))
  21.                 {
  22.                     for (int j = 0; j < num.Length; j++)
  23.                     {
  24.                         tempSum += int.Parse(num[j].ToString());
  25.                     }
  26.                     if (tempSum == sum && num.Length == 9)
  27.                     {
  28.                         Console.WriteLine(num);
  29.                         OK = true;
  30.                     }
  31.                 }
  32.             }
  33.             if (!OK)
  34.             {
  35.                 Console.WriteLine("NO");
  36.             }
  37.  
  38. 2 variant
  39.  
  40.  
  41.             int sum = int.Parse(Console.ReadLine());
  42.                         int diff = int.Parse(Console.ReadLine());
  43.                         bool OK = false;
  44.  
  45.             string num;
  46.             for (int i = 100; i < 1000; i++)
  47.             {
  48.  
  49.                 int tempSum = 0;
  50.                 int a = i;
  51.                 int b = a + diff;
  52.                 int c = b + diff;
  53.                 //string num = "";
  54.                
  55.  
  56.                 num = a.ToString() + b.ToString() + c.ToString();
  57.                 Regex r = new Regex("0|1|2|3|4");
  58.                 if (!r.IsMatch(num))  // (!num.Contains("0") && !num.Contains("8") && !num.Contains("9"))
  59.                 {
  60.                     for (int j = 0; j < num.Length; j++)
  61.                     {
  62.                         tempSum += int.Parse(num[j].ToString());
  63.                     }
  64.                     if (tempSum == sum && num.Length == 9)
  65.                     {
  66.                         Console.WriteLine(num);
  67.                         OK = true;
  68.                     }
  69.                 }
  70.             }
  71.             if(!OK)
  72.          {
  73.                         Console.WriteLine("No");
  74.          }
  75.  
  76.  
  77. 3 variant
  78.  
  79.  
  80.             int diff = int.Parse(Console.ReadLine());
  81.              
  82.                 String[] letter = {"k","n","p","s"};
  83.                 int[] letterValue = {1, 4, 5, 3};
  84.                 bool foundResult = false;
  85.                 List<string> resultList = new List<string>();
  86.                
  87.                 if(diff <= 16){// zashtoto ne moje da ima diff po-golqmo ot 16 max e 20 - 4 = 16
  88.                         for(int i1 =0; i1 < letter.Length; i1++){
  89.                                 for(int i2 =0; i2 < letter.Length; i2++){
  90.                                         for(int i3 =0; i3 < letter.Length; i3++){
  91.                                                 for(int i4 =0; i4 < letter.Length; i4++){
  92.                                                         for(int i5 =0; i5 < letter.Length; i5++){
  93.                                                                 for(int i6 =0; i6 < letter.Length; i6++){
  94.                                                                         for(int i7 =0; i7 < letter.Length; i7++){
  95.                                                                                 for(int i8 =0; i8 < letter.Length; i8++){
  96.                                                                                        
  97.                         String wholeSequence =letter[i1]+
  98.                                         letter[i2]+
  99.                                         letter[i3]+
  100.                                         letter[i4]+
  101.                                         letter[i5]+
  102.                                         letter[i6]+
  103.                                         letter[i7]+
  104.                                         letter[i8];
  105.                                                                                                        
  106.                         int firstFourLetters = letterValue[i8]+
  107.                                         letterValue[i7]+
  108.                                         letterValue[i6]+
  109.                                         letterValue[i5];
  110.                        
  111.                         int secondFourLetters = letterValue[i4]+
  112.                                         letterValue[i3]+
  113.                                         letterValue[i2]+
  114.                                         letterValue[i1];
  115.                                        
  116.                         if(firstFourLetters - secondFourLetters == diff || secondFourLetters - firstFourLetters == diff){
  117.                                 foundResult = true;
  118.                                 //System.out.println(wholeSequence);/// 1 variant
  119.                                 resultList.Add(wholeSequence);// 2 variant sus sortirane na ArrayList
  120.                         }
  121.                                                                                        
  122.                                                                                 }
  123.                                                                         }
  124.                                                                 }
  125.                                                         }
  126.                                                 }
  127.                                         }
  128.                                 }
  129.                         }
  130.                 }
  131.                
  132.                
  133.                 if(!foundResult){
  134.                         Console.WriteLine("NO");
  135.                 }
  136.                 else
  137.                 {
  138.  
  139.                 resultList.Sort();
  140.                 foreach (string s in resultList){
  141.                         Console.WriteLine(s);
  142.                 }
  143.                 }
  144.            
  145.             }
  146.  
  147.  
  148. 4 variant
  149.  
  150. using System;
  151. using System.Collections.Generic;
  152. using System.Linq;
  153. using System.Text;
  154. using System.Threading.Tasks;
  155.  
  156. namespace ConsoleApplication1
  157. {
  158.     class Program
  159.     {
  160.         static void Main(string[] args)
  161.         {
  162.  
  163.             int trib1 = int.Parse(Console.ReadLine());
  164.             int trib2 = int.Parse(Console.ReadLine());
  165.             int trib3 = int.Parse(Console.ReadLine());
  166.             int instalNum = int.Parse(Console.ReadLine());
  167.             int step = int.Parse(Console.ReadLine());
  168.  
  169.            // bool isCrossed = false;
  170.             int currentNum = 0;
  171.  
  172.             bool[] isTribonacci = new bool[1000000 + 1];
  173.  
  174.             isTribonacci[trib1] = true;
  175.             isTribonacci[trib2] = true;
  176.             isTribonacci[trib3] = true;
  177.  
  178.             while (true)
  179.             {
  180.                 currentNum = trib1 + trib2 + trib3;
  181.                 trib1 = trib2;
  182.                 trib2 = trib3;
  183.                 trib3 = currentNum;
  184.  
  185.                 if (currentNum > 1000000)
  186.                 {
  187.                     break;
  188.                 }
  189.                 isTribonacci[currentNum] = true;
  190.             }
  191.  
  192.             int counter = 1;
  193.             bool isCrossed = false;
  194.             while (instalNum <= 1000000)
  195.             {
  196.                 if (isTribonacci[instalNum] == true)
  197.                 {
  198.                     isCrossed = true;
  199.                     Console.WriteLine(instalNum);
  200.                     break;
  201.                 }
  202.                 instalNum += step * (counter / 2);
  203.                 counter++;
  204.             }
  205.  
  206.             if (!isCrossed)
  207.             {
  208.                 Console.WriteLine("No");
  209.             }
  210.  
  211.         }
  212.     }
  213. }
  214.  
  215. 5 variant
  216.  
  217.             int startYear = int.Parse(Console.ReadLine());
  218.             int endYear = int.Parse(Console.ReadLine());
  219.             int magic = int.Parse(Console.ReadLine());
  220.  
  221.             bool hasAnswer = false;
  222.  
  223.             string date;
  224.             int tempweight;
  225.  
  226.             for (int year = startYear; year <= endYear; year++)
  227.             {
  228.                 for (int month = 1; month <= 12; month++)
  229.                 {
  230.                     for (int day = 1; day <= 31; day++)
  231.                     {
  232.                         tempweight = 0;
  233.                         if((!DateTime.IsLeapYear(year) && month == 2 && day > 28) ||
  234.                         (DateTime.IsLeapYear(year) && month == 2 && day > 29 ||
  235.                         (day == 31 && (month == 4 || month == 6 || month == 9 || month == 11))))
  236.                         {
  237.  
  238.                         continue;
  239.                         }
  240.                         else
  241.                         {
  242.                             date = "" + day + month + year;
  243.                             for (int i = 0; i < date.Length; i++)
  244.                             {
  245.                                 int a = int.Parse(date[i].ToString());
  246.                                 for (int j =  i+1; j < date.Length; j++)
  247.                                             {
  248.                                               int b = int.Parse(date[j].ToString());
  249.                                     tempweight += a * b;
  250.                                             }
  251.                             }
  252.  
  253.                             if (tempweight == magic)
  254.                             {
  255.                                 DateTime printDate = new DateTime(year, month , day);
  256.                                 Console.WriteLine(printDate.ToString("dd-MM-yyyy"));
  257.                                 hasAnswer = true;
  258.                             }
  259.                         }
  260.  
  261.  
  262.                     }
  263.                 }
  264.             }
  265.  
  266.             if (!hasAnswer)
  267.             {
  268.                 Console.WriteLine("No");
  269.             }
  270.  
  271. variant 6
  272.  
  273.  
  274.             int start = int.Parse(Console.ReadLine());
  275.             int end = int.Parse(Console.ReadLine());
  276.  
  277.             Dictionary<char, int> values = new Dictionary<char, int>()
  278.             { { 'a', 5 }, { 'b', -12 }, { 'c', 47 }, { 'd', 7 }, { 'e', -32 } };
  279.  
  280.             bool noResults = true;
  281.  
  282.             for(char c1 = 'a'; c1<= 'e'; c1++)
  283.             {
  284.                 for(char c2 = 'a'; c2<= 'e'; c2++)
  285.             {
  286.                     for(char c3 = 'a'; c3<= 'e'; c3++)
  287.             {
  288.                         for(char c4 = 'a'; c4<= 'e'; c4++)
  289.             {
  290.                             for(char c5 = 'a'; c5<= 'e'; c5++)
  291.             {
  292.                  string word = "" + c1 + c2 + c3 + c4 + c5;
  293.                                 string weightWord = "" + c1;
  294.  
  295.                                 foreach (var character in word)
  296.                                 {
  297.                                     if(!weightWord.Contains(character.ToString()))
  298.                                     {
  299.                                         weightWord += character;
  300.                                     }
  301.  
  302.                                 }
  303.  
  304.                                 long currentWeight = CalculateWeight(weightWord, values);
  305.  
  306.                                 if (currentWeight >= start && currentWeight <= end)
  307.                                 {
  308.                                     Console.Write(word + " ");
  309.                                     noResults = false;
  310.                                 }
  311.                             }
  312.                         }
  313.                     }
  314.                 }
  315.             }
  316.    
  317.             if (noResults)
  318.             {
  319.                 Console.WriteLine("No");
  320.             }
  321.  
  322.         }
  323.  
  324.         static long CalculateWeight (string word , Dictionary<char, int> value)
  325.         {
  326.             long weight = 0;
  327.             int multiplyer = 1;
  328.             foreach (var currentChar in word)
  329.             {
  330.                 weight += multiplyer * value[currentChar];
  331.                 multiplyer++;
  332.             }
  333.            return weight;
  334.  
  335.  
  336. 7 variant
  337.  
  338.  string word = Console.ReadLine();
  339.         int n = int.Parse(Console.ReadLine());
  340.         string longestWord = string.Empty;
  341.  
  342.         for (int row = 0; row < n; row++)
  343.         {
  344.             for (int col = 0; col < n; col++)
  345.             {
  346.                 string leftWord = FindAlphabeticalWord(word, n, row, col, -1, 0);
  347.                 longestWord = CompareWords(leftWord, longestWord);
  348.                 string rightWord = FindAlphabeticalWord(word, n, row, col, 1, 0);
  349.                 longestWord = CompareWords(rightWord, longestWord);
  350.                 string upWord = FindAlphabeticalWord(word, n, row, col, 0, -1);
  351.                 longestWord = CompareWords(upWord, longestWord);
  352.                 string downWord = FindAlphabeticalWord(word, n, row, col, 0, 1);
  353.                 longestWord = CompareWords(downWord, longestWord);              
  354.             }
  355.         }
  356.         Console.WriteLine(longestWord);
  357.     }
  358.  
  359.     private static string CompareWords(string leftWord, string longestWord)
  360.     {
  361.         if (leftWord.Length > longestWord.Length ||
  362.             (leftWord.Length == longestWord.Length && //this was the missing equation
  363.             leftWord.CompareTo(longestWord) < 0 ))
  364.         {
  365.             return leftWord;
  366.         }
  367.         return longestWord;
  368.     }
  369.  
  370.     private static string FindAlphabeticalWord(string word, int n, int row, int col, int directionX, int directionY)
  371.     {
  372.         char currentLetter = GetCharAtPosition(word, n, row, col);
  373.         List<char> alphabeticalWord = new List<char>();
  374.         alphabeticalWord.Add(currentLetter);
  375.  
  376.         while (true)
  377.         {
  378.             row = row + directionY;
  379.             col = col + directionX;
  380.             if ((row < 0 || row >=n) || (col <0 || col >=n))
  381.             {
  382.                 break;
  383.             }
  384.  
  385.             char nextLetter = GetCharAtPosition(word, n, row, col);
  386.  
  387.             if (currentLetter >= nextLetter)
  388.             {
  389.                 break;
  390.             }
  391.             alphabeticalWord.Add(nextLetter);
  392.             currentLetter = nextLetter;
  393.         }
  394.         string currentWord = new string(alphabeticalWord.ToArray());
  395.         return currentWord;
  396.     }
  397.  
  398.     private static char GetCharAtPosition(string word, int n, int row, int col)
  399.     {
  400.         char currentLetter = word[(row * n + col) % word.Length];
  401.         return currentLetter;
  402.     }
  403. }
  404.  
  405.  
  406.  
  407.  
  408.     8 variant
  409.  
  410. static int count = 0;
  411.     static void Main()
  412.     {
  413.         int weight = int.Parse(Console.ReadLine());
  414.  
  415.         char[] letters = { 'A', 'B', 'C', 'E', 'H', 'K', 'M', 'P', 'T', 'X' };
  416.  
  417.         for (int letter1 = 0; letter1 < letters.Length; letter1++)
  418.         {
  419.             for (int letter2 = 0; letter2 < letters.Length; letter2++)
  420.             {
  421.                 for (int a = 0; a <= 9; a++)
  422.                 {
  423.                     string carNumber = "CA" + a + a + a + a + letters[letter1] + letters[letter2];
  424.                     CheckCarNumberForMagic(carNumber, weight);
  425.                     for (int b = 0; b <= 9 ; b++)
  426.                     {
  427.                         if (b != a)
  428.                         {
  429.                             CheckCarNumberForMagic("CA" + a + b + b + b + letters[letter1] + letters[letter2], weight);
  430.                             CheckCarNumberForMagic("CA" + a + a + a + b + letters[letter1] + letters[letter2], weight);
  431.                             CheckCarNumberForMagic("CA" + a + a + b + b + letters[letter1] + letters[letter2], weight);
  432.                             CheckCarNumberForMagic("CA" + a + b + a + b + letters[letter1] + letters[letter2], weight);
  433.                             CheckCarNumberForMagic("CA" + a + b + b + a + letters[letter1] + letters[letter2], weight);
  434.                             //"CAabbbXY", "CAaaabXY", "CAaabbXY", "CAababXY" and "CAabbaXY"
  435.                         }
  436.                     }
  437.                 }
  438.             }
  439.         }
  440.         Console.WriteLine(count);
  441.     }
  442.  
  443.     private static void CheckCarNumberForMagic(string carNumber, int weight)
  444.     {
  445.         int tempWeight = 0;
  446.         foreach (var ch in carNumber)
  447.         {
  448.             if (ch >= '0' && ch <= '9')
  449.             {
  450.                 tempWeight += ch - '0';
  451.             }
  452.             else
  453.             {
  454.                 tempWeight += (ch - 64) * 10;
  455.             }
  456.         }
  457.  
  458.         if (tempWeight == weight)
  459.         {
  460.             count++;
  461.         }      
  462.     }
  463. }
  464.  
  465.  
  466. 28 april ////////////////////////////////////////////////
  467.  
  468.  
  469.  
  470.             int targetWeight = int.Parse(Console.ReadLine());
  471.  
  472.             string[] cardFaces = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A" };
  473.             string[] cardSuits = { "Clubs", "Diamonds", "Hearts", "Spades" };
  474.             int count = 0;
  475.             for (int face = 0; face < cardFaces.Length - 4; face++)
  476.             {
  477.                 for (int suit1 = 0; suit1 < cardSuits.Length; suit1++)
  478.                 {
  479.                     for (int suit2 = 0; suit2 < cardSuits.Length; suit2++)
  480.                     {
  481.                         for (int suit3 = 0; suit3 < cardSuits.Length; suit3++)
  482.                         {
  483.                             for (int suit4 = 0; suit4 < cardSuits.Length; suit4++)
  484.                             {
  485.                                 for (int suit5 = 0; suit5 < cardSuits.Length; suit5++)
  486.                                 {
  487.                                     int weight =
  488.                                         (face + 1) * 10 + suit1 + 1 +
  489.                                         (face + 2) * 20 + suit2 + 1 +
  490.                                         (face + 3) * 30 + suit3 + 1 +
  491.                                         (face + 4) * 40 + suit4 + 1 +
  492.                                         (face + 5) * 50 + suit5 + 1;
  493.                                     if (weight == targetWeight)
  494.                                     {
  495.                                         count++;
  496.  
  497.                                         // Print the straight hand + its weight
  498.                                         //string card1 = cardFaces[face + 0] + cardSuits[suit1][0];
  499.                                         //string card2 = cardFaces[face + 1] + cardSuits[suit2][0];
  500.                                         //string card3 = cardFaces[face + 2] + cardSuits[suit3][0];
  501.                                         //string card4 = cardFaces[face + 3] + cardSuits[suit4][0];
  502.                                         //string card5 = cardFaces[face + 4] + cardSuits[suit5][0];
  503.                                         //Console.WriteLine("({0} {1} {2} {3} {4}) -> weight {5}",
  504.                                         //    card1, card2, card3, card4, card5, weight);
  505.                                     }
  506.                                 }
  507.                             }
  508.                         }
  509.                     }
  510.                 }
  511.             }
  512.             Console.WriteLine(count);
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519. 26 AVGUST //////////////////////////////////////
  520.  
  521.  
  522. string input = Console.ReadLine();
  523.             input = input.ToLower();
  524.             int letSum = 0;
  525.             bool hasWinningNumbers = false;
  526.             for (int i = 0; i < input.Length; i++)
  527.             {
  528.                 letSum += input[i] - 'a' + 1;
  529.             }
  530.  
  531.             for (int i = 1; i < 10; i++)
  532.             {
  533.                 for (int j = 1; j < 10; j++)
  534.                 {
  535.                     for (int k = 1; k < 10; k++)
  536.                     {
  537.                         for (int l = 1; l < 10; l++)
  538.                         {
  539.                             for (int m = 1; m < 10; m++)
  540.                             {
  541.                                 for (int n = 1; n < 10; n++)
  542.                                 {
  543.                                     if (i * j * k == letSum && i * j * k == l * m * n)
  544.                                     {
  545.                                         Console.WriteLine("{0}{1}{2}-{3}{4}{5}",
  546.                                             i, j, k, l, m, n);
  547.                                         hasWinningNumbers = true;
  548.                                     }
  549.                                 }
  550.                             }
  551.                         }
  552.                     }
  553.                 }
  554.             }
  555.             if (!hasWinningNumbers)
  556.             {
  557.                 Console.WriteLine("No");
  558.             }
  559.  
  560. //////////////// 25 july morning ////////////////////////////
  561.  
  562.  
  563.  Dictionary<int, string> morseEncoding = new Dictionary<int, string>
  564.         {
  565.             {1, ".----"},
  566.             {2, "..---"},
  567.             {3, "...--"},
  568.             {4, "....-"},
  569.             {5, "....."}
  570.         };
  571.  
  572.         int n = int.Parse(Console.ReadLine()); //1234
  573.         int nSum = 0;
  574.         bool hasAnwer = false;
  575.  
  576.         while (n != 0)
  577.         {
  578.             //Getting the current digit of the number
  579.             int remainder = n % 10;
  580.             //Summing up the digit to the total sum
  581.             nSum += remainder;
  582.             //Removing the last digit from the number
  583.             n /= 10;
  584.         }
  585.  
  586.         for (int i = 1; i <= 5; i++)
  587.         {
  588.             for (int j = 1; j <= 5; j++)
  589.             {
  590.                 for (int k = 1; k <= 5; k++)
  591.                 {
  592.                     for (int l = 1; l <= 5; l++)
  593.                     {
  594.                         for (int m = 1; m <= 5; m++)
  595.                         {
  596.                             for (int o = 1; o <= 5; o++)
  597.                             {
  598.                                 int product = i*j*k*l*m*o;
  599.                                 if (product == nSum)
  600.                                 {
  601.                                     Console.WriteLine(morseEncoding[i] + '|' +
  602.                                                         morseEncoding[j] + '|' +
  603.                                                         morseEncoding[k] + '|' +
  604.                                                         morseEncoding[l] + '|' +
  605.                                                         morseEncoding[m] + '|' +
  606.                                                         morseEncoding[o] + '|');
  607.                                     hasAnwer = true;
  608.                                 }
  609.                             }
  610.                         }
  611.                     }
  612.                 }
  613.             }
  614.         }
  615.  
  616.         if(hasAnwer != true)
  617.             Console.WriteLine("No");
  618.        
  619.  
  620.  
  621.  
  622.  
  623.  
  624. /////////////////////////////// 25 july evening   //////////
  625.  
  626.  
  627. using System;
  628. using System.Collections.Generic;
  629. using System.Linq;
  630. using System.Text;
  631.  
  632. namespace ConsoleApplication1
  633. {
  634.     class Program
  635.     {
  636.         static void Main(string[] args)
  637.         {
  638.  
  639.  
  640.         string firstWord = Console.ReadLine();
  641.         string secondWord = Console.ReadLine();
  642.         int maxWeight = int.Parse(Console.ReadLine());
  643.  
  644.         bool resultFound = false;
  645.  
  646.         for (int firstDivider = 1; firstDivider < firstWord.Length; firstDivider++)
  647.         {
  648.             for (int secondDivider = 1; secondDivider < secondWord.Length; secondDivider++)
  649.             {
  650.                 string firstLeft = firstWord.Substring(0, firstDivider);
  651.                 string firstRight = firstWord.Substring(firstDivider);
  652.                 string secondLeft = secondWord.Substring(0, secondDivider);
  653.                 string secondRight = secondWord.Substring(secondDivider);
  654.                 //Console.Write("{0}|{1}", firstLeft, firstRight);
  655.                 //Console.WriteLine("      {0}|{1}", secondLeft, secondRight);
  656.  
  657.                
  658.  
  659.                 long sum = 0;
  660.                 for (int i = 0; i < firstLeft.Length; i++)
  661.                 {
  662.                     sum += (int)firstLeft[i];
  663.                 }
  664.                 long sum1 = 0;
  665.                 for (int i = 0; i < firstRight.Length; i++)
  666.                 {
  667.                     sum1 += (int)firstRight[i];
  668.                 }
  669.                 long sum2 = 0;
  670.                 for (int i = 0; i < secondLeft.Length; i++)
  671.                 {
  672.                     sum2 += (int)secondLeft[i];
  673.                 }
  674.                 long sum3 = 0;
  675.                 for (int i = 0; i < secondRight.Length; i++)
  676.                 {
  677.                     sum3 += (int)secondRight[i];
  678.                 }
  679.  
  680.                // long firstLeftWeight = CalculateWeight(firstLeft);
  681.              //   long firstRightWeight = CalculateWeight(firstRight);
  682.               //  long secondLeftWeight = CalculateWeight(secondLeft);
  683.               //  long secondRightWeight = CalculateWeight(secondRight);
  684.                 //Console.Write("{0}|{1}", firstLeftWeight, firstRightWeight);
  685.                 //Console.WriteLine("      {0}|{1}", secondLeftWeight, secondRightWeight);
  686.  
  687.                 long nakovWeight = Math.Abs(
  688.                     sum * sum3 - sum1 * sum2);
  689.                 if (nakovWeight <= maxWeight)
  690.                 {
  691.                     resultFound = true;
  692.                     Console.WriteLine("({0}|{1}) matches ({2}|{3}) by {4} nakovs",
  693.                         firstLeft, firstRight, secondLeft, secondRight, nakovWeight);
  694.                 }
  695.             }
  696.         }
  697.  
  698.         if (!resultFound)
  699.         {
  700.             Console.WriteLine("No");
  701.         }
  702.     }
  703.  
  704.     static long CalculateWeight(string word)
  705.     {
  706.         long sum = 0;
  707.         for (int i = 0; i < word.Length; i++)
  708.         {
  709.             sum += (int)word[i];
  710.         }
  711.  
  712.         return sum;
  713.     }
  714. }
  715.  
  716.   }
  717.    
  718.  
  719. /////////////// 22 avgust    //////////////////
  720.  
  721.  
  722. int size =int.Parse(Console.ReadLine());
  723.             int distance = int.Parse(Console.ReadLine());
  724.             int counter = 0;
  725.  
  726.             for (int row = 1; row <= size; row++)
  727.             {
  728.                 for (int column = 0; column <= size; column++)
  729.                 {
  730.                     //1
  731.                     if (column + distance + 1 <= size)
  732.                     {
  733.                         Console.WriteLine("{0} - {1}", "" + (char)(96 + row) + column
  734.                             , "" + (char)(96 + row) + (column + distance + 1));
  735.  
  736.                         Console.WriteLine("{1} - {0}", "" + (char)(96 + row) + column
  737.                             , "" + (char)(96 + row) + (column + distance + 1));
  738.  
  739.                         counter += 2;
  740.                      }
  741.                     //2
  742.                     if (row + distance + 1 <= size)
  743.                     {
  744.                         Console.WriteLine("{0} - {1}", "" + (char)(96 + row) + column
  745.                             , "" + (char)(96 + row + distance + 1) + column);
  746.  
  747.                         Console.WriteLine("{1} - {0}", "" + (char)(96 + row) + column
  748.                             , "" + (char)(96 + row + distance + 1) + column);
  749.  
  750.                         counter += 2;
  751.                     }
  752.  
  753.                     //3
  754.                     if (row + distance + 1 <= size && column + distance + 1 <= size)
  755.                     {
  756.                         Console.WriteLine("{0} - {1}", "" + (char)(96 + row) + column
  757.                             , "" + (char)(96 + row + distance + 1) + (column + distance + 1));
  758.  
  759.                         Console.WriteLine("{1} - {0}", "" + (char)(96 + row) + column
  760.                             , "" + (char)(96 + row + distance + 1) + (column + distance + 1));
  761.  
  762.                         counter += 2;
  763.                     }
  764.  
  765.  
  766.                     //4
  767.                     if (row + distance + 1 <= size && column - distance - 1 > 0)
  768.                     {
  769.                         Console.WriteLine("{0} - {1}", "" + (char)(96 + row) + column
  770.                             , "" + (char)(96 + row + distance + 1) + (column - distance));
  771.  
  772.                         Console.WriteLine("{1} - {0}", "" + (char)(96 + row) + column
  773.                             , "" + (char)(96 + row + distance + 1) + (column - distance));
  774.  
  775.                         counter += 2;
  776.                     }
  777.  
  778.                 }
  779.             }
  780.             if(counter == 0)
  781.             {
  782.                 Console.WriteLine("No valid positions");
  783.             }            
  784.         }
  785.  
  786.  
  787.  
  788. //////////////////// 7 noemvri   ////////////////////////
  789.  
  790.  
  791.  string input = Console.ReadLine();
  792.         int targetCount = int.Parse(Console.ReadLine());
  793.         bool resultFound = false;
  794.  
  795.         int count = 0;
  796.         for (int first = 0; first < input.Length; first++)
  797.         {
  798.             for (int second = 0; second < input.Length; second++)
  799.             {
  800.                 for (int third = 0; third < input.Length; third++)
  801.                 {
  802.                     for (int fourth = 0; fourth < input.Length; fourth++)
  803.                     {
  804.                         for (int fifth = 0; fifth < input.Length; fifth++)
  805.                         {
  806.                             if (count == targetCount)
  807.                             {
  808.                                 string output = "" + input[first] + input[second] + input[third]
  809.                                     + input[fourth] + input[fifth];
  810.  
  811.                                 Console.WriteLine(output);
  812.                                 resultFound = true;
  813.                             }
  814.  
  815.                             count++;
  816.                         }
  817.                     }
  818.                 }
  819.             }
  820.         }
  821.  
  822.         if (!resultFound)
  823.         {
  824.             Console.WriteLine("No");
  825.         }
  826.  
  827.  
  828.  
  829. ///////////////  8 noemvri  ///////////////////
  830.  
  831.  
  832. decimal cash = decimal.Parse(Console.ReadLine());
  833.         string[] housesHand = Console.ReadLine().Split();
  834.  
  835.         int housesStrength = 0;
  836.  
  837.         foreach (var card in housesHand)
  838.         {
  839.             switch (card)
  840.             {
  841.                 case "J": housesStrength += 11;
  842.                     break;
  843.                 case "Q": housesStrength += 12;
  844.                     break;
  845.                 case "K": housesStrength += 13;
  846.                     break;
  847.                 case "A": housesStrength += 14;
  848.                     break;
  849.                 default: housesStrength += int.Parse(card);
  850.                     break;
  851.             }
  852.         }
  853.  
  854.         int countWinning = 0;
  855.         int totalHands = 0;
  856.  
  857.         for (int card1 = 2; card1 < 15; card1++)
  858.         {
  859.             for (int card2 = 2; card2 < 15; card2++)
  860.             {
  861.                 for (int card3 = 2; card3 < 15; card3++)
  862.                 {
  863.                     for (int card4 = 2; card4 < 15; card4++)
  864.                     {
  865.                         int myPower = card1 + card2 + card3 + card4;
  866.  
  867.                         if (myPower > housesStrength)
  868.                         {
  869.                             countWinning++;
  870.                         }
  871.                         totalHands++;
  872.                     }
  873.                 }
  874.             }
  875.         }
  876.  
  877.         decimal probability = (decimal)countWinning / totalHands;
  878.  
  879.         if (probability < 0.5m)
  880.         {
  881.             Console.WriteLine("FOLD");
  882.         }
  883.         else
  884.         {
  885.             Console.WriteLine("DRAW");
  886.         }
  887.  
  888.         decimal expectedWinnings = probability * 2 * cash;
  889.         Console.WriteLine("{0:f2}", expectedWinnings);
  890.     }
  891. }
  892.  
  893.  
  894. //////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement