Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- variant 1
- int sum = int.Parse(Console.ReadLine());
- int diff = int.Parse(Console.ReadLine());
- bool OK = false;
- string num;
- for (int i = 111; i < 778; i++)
- {
- int tempSum = 0;
- int a = i;
- int b = a + diff;
- int c = b + diff;
- //string num = "";
- num = a.ToString() + b.ToString() + c.ToString();
- Regex r = new Regex("0|8|9");
- if (!r.IsMatch(num)) // (!num.Contains("0") && !num.Contains("8") && !num.Contains("9"))
- {
- for (int j = 0; j < num.Length; j++)
- {
- tempSum += int.Parse(num[j].ToString());
- }
- if (tempSum == sum && num.Length == 9)
- {
- Console.WriteLine(num);
- OK = true;
- }
- }
- }
- if (!OK)
- {
- Console.WriteLine("NO");
- }
- 2 variant
- int sum = int.Parse(Console.ReadLine());
- int diff = int.Parse(Console.ReadLine());
- bool OK = false;
- string num;
- for (int i = 100; i < 1000; i++)
- {
- int tempSum = 0;
- int a = i;
- int b = a + diff;
- int c = b + diff;
- //string num = "";
- num = a.ToString() + b.ToString() + c.ToString();
- Regex r = new Regex("0|1|2|3|4");
- if (!r.IsMatch(num)) // (!num.Contains("0") && !num.Contains("8") && !num.Contains("9"))
- {
- for (int j = 0; j < num.Length; j++)
- {
- tempSum += int.Parse(num[j].ToString());
- }
- if (tempSum == sum && num.Length == 9)
- {
- Console.WriteLine(num);
- OK = true;
- }
- }
- }
- if(!OK)
- {
- Console.WriteLine("No");
- }
- 3 variant
- int diff = int.Parse(Console.ReadLine());
- String[] letter = {"k","n","p","s"};
- int[] letterValue = {1, 4, 5, 3};
- bool foundResult = false;
- List<string> resultList = new List<string>();
- if(diff <= 16){// zashtoto ne moje da ima diff po-golqmo ot 16 max e 20 - 4 = 16
- for(int i1 =0; i1 < letter.Length; i1++){
- for(int i2 =0; i2 < letter.Length; i2++){
- for(int i3 =0; i3 < letter.Length; i3++){
- for(int i4 =0; i4 < letter.Length; i4++){
- for(int i5 =0; i5 < letter.Length; i5++){
- for(int i6 =0; i6 < letter.Length; i6++){
- for(int i7 =0; i7 < letter.Length; i7++){
- for(int i8 =0; i8 < letter.Length; i8++){
- String wholeSequence =letter[i1]+
- letter[i2]+
- letter[i3]+
- letter[i4]+
- letter[i5]+
- letter[i6]+
- letter[i7]+
- letter[i8];
- int firstFourLetters = letterValue[i8]+
- letterValue[i7]+
- letterValue[i6]+
- letterValue[i5];
- int secondFourLetters = letterValue[i4]+
- letterValue[i3]+
- letterValue[i2]+
- letterValue[i1];
- if(firstFourLetters - secondFourLetters == diff || secondFourLetters - firstFourLetters == diff){
- foundResult = true;
- //System.out.println(wholeSequence);/// 1 variant
- resultList.Add(wholeSequence);// 2 variant sus sortirane na ArrayList
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- if(!foundResult){
- Console.WriteLine("NO");
- }
- else
- {
- resultList.Sort();
- foreach (string s in resultList){
- Console.WriteLine(s);
- }
- }
- }
- 4 variant
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- int trib1 = int.Parse(Console.ReadLine());
- int trib2 = int.Parse(Console.ReadLine());
- int trib3 = int.Parse(Console.ReadLine());
- int instalNum = int.Parse(Console.ReadLine());
- int step = int.Parse(Console.ReadLine());
- // bool isCrossed = false;
- int currentNum = 0;
- bool[] isTribonacci = new bool[1000000 + 1];
- isTribonacci[trib1] = true;
- isTribonacci[trib2] = true;
- isTribonacci[trib3] = true;
- while (true)
- {
- currentNum = trib1 + trib2 + trib3;
- trib1 = trib2;
- trib2 = trib3;
- trib3 = currentNum;
- if (currentNum > 1000000)
- {
- break;
- }
- isTribonacci[currentNum] = true;
- }
- int counter = 1;
- bool isCrossed = false;
- while (instalNum <= 1000000)
- {
- if (isTribonacci[instalNum] == true)
- {
- isCrossed = true;
- Console.WriteLine(instalNum);
- break;
- }
- instalNum += step * (counter / 2);
- counter++;
- }
- if (!isCrossed)
- {
- Console.WriteLine("No");
- }
- }
- }
- }
- 5 variant
- int startYear = int.Parse(Console.ReadLine());
- int endYear = int.Parse(Console.ReadLine());
- int magic = int.Parse(Console.ReadLine());
- bool hasAnswer = false;
- string date;
- int tempweight;
- for (int year = startYear; year <= endYear; year++)
- {
- for (int month = 1; month <= 12; month++)
- {
- for (int day = 1; day <= 31; day++)
- {
- tempweight = 0;
- if((!DateTime.IsLeapYear(year) && month == 2 && day > 28) ||
- (DateTime.IsLeapYear(year) && month == 2 && day > 29 ||
- (day == 31 && (month == 4 || month == 6 || month == 9 || month == 11))))
- {
- continue;
- }
- else
- {
- date = "" + day + month + year;
- for (int i = 0; i < date.Length; i++)
- {
- int a = int.Parse(date[i].ToString());
- for (int j = i+1; j < date.Length; j++)
- {
- int b = int.Parse(date[j].ToString());
- tempweight += a * b;
- }
- }
- if (tempweight == magic)
- {
- DateTime printDate = new DateTime(year, month , day);
- Console.WriteLine(printDate.ToString("dd-MM-yyyy"));
- hasAnswer = true;
- }
- }
- }
- }
- }
- if (!hasAnswer)
- {
- Console.WriteLine("No");
- }
- variant 6
- int start = int.Parse(Console.ReadLine());
- int end = int.Parse(Console.ReadLine());
- Dictionary<char, int> values = new Dictionary<char, int>()
- { { 'a', 5 }, { 'b', -12 }, { 'c', 47 }, { 'd', 7 }, { 'e', -32 } };
- bool noResults = true;
- for(char c1 = 'a'; c1<= 'e'; c1++)
- {
- for(char c2 = 'a'; c2<= 'e'; c2++)
- {
- for(char c3 = 'a'; c3<= 'e'; c3++)
- {
- for(char c4 = 'a'; c4<= 'e'; c4++)
- {
- for(char c5 = 'a'; c5<= 'e'; c5++)
- {
- string word = "" + c1 + c2 + c3 + c4 + c5;
- string weightWord = "" + c1;
- foreach (var character in word)
- {
- if(!weightWord.Contains(character.ToString()))
- {
- weightWord += character;
- }
- }
- long currentWeight = CalculateWeight(weightWord, values);
- if (currentWeight >= start && currentWeight <= end)
- {
- Console.Write(word + " ");
- noResults = false;
- }
- }
- }
- }
- }
- }
- if (noResults)
- {
- Console.WriteLine("No");
- }
- }
- static long CalculateWeight (string word , Dictionary<char, int> value)
- {
- long weight = 0;
- int multiplyer = 1;
- foreach (var currentChar in word)
- {
- weight += multiplyer * value[currentChar];
- multiplyer++;
- }
- return weight;
- 7 variant
- string word = Console.ReadLine();
- int n = int.Parse(Console.ReadLine());
- string longestWord = string.Empty;
- for (int row = 0; row < n; row++)
- {
- for (int col = 0; col < n; col++)
- {
- string leftWord = FindAlphabeticalWord(word, n, row, col, -1, 0);
- longestWord = CompareWords(leftWord, longestWord);
- string rightWord = FindAlphabeticalWord(word, n, row, col, 1, 0);
- longestWord = CompareWords(rightWord, longestWord);
- string upWord = FindAlphabeticalWord(word, n, row, col, 0, -1);
- longestWord = CompareWords(upWord, longestWord);
- string downWord = FindAlphabeticalWord(word, n, row, col, 0, 1);
- longestWord = CompareWords(downWord, longestWord);
- }
- }
- Console.WriteLine(longestWord);
- }
- private static string CompareWords(string leftWord, string longestWord)
- {
- if (leftWord.Length > longestWord.Length ||
- (leftWord.Length == longestWord.Length && //this was the missing equation
- leftWord.CompareTo(longestWord) < 0 ))
- {
- return leftWord;
- }
- return longestWord;
- }
- private static string FindAlphabeticalWord(string word, int n, int row, int col, int directionX, int directionY)
- {
- char currentLetter = GetCharAtPosition(word, n, row, col);
- List<char> alphabeticalWord = new List<char>();
- alphabeticalWord.Add(currentLetter);
- while (true)
- {
- row = row + directionY;
- col = col + directionX;
- if ((row < 0 || row >=n) || (col <0 || col >=n))
- {
- break;
- }
- char nextLetter = GetCharAtPosition(word, n, row, col);
- if (currentLetter >= nextLetter)
- {
- break;
- }
- alphabeticalWord.Add(nextLetter);
- currentLetter = nextLetter;
- }
- string currentWord = new string(alphabeticalWord.ToArray());
- return currentWord;
- }
- private static char GetCharAtPosition(string word, int n, int row, int col)
- {
- char currentLetter = word[(row * n + col) % word.Length];
- return currentLetter;
- }
- }
- 8 variant
- static int count = 0;
- static void Main()
- {
- int weight = int.Parse(Console.ReadLine());
- char[] letters = { 'A', 'B', 'C', 'E', 'H', 'K', 'M', 'P', 'T', 'X' };
- for (int letter1 = 0; letter1 < letters.Length; letter1++)
- {
- for (int letter2 = 0; letter2 < letters.Length; letter2++)
- {
- for (int a = 0; a <= 9; a++)
- {
- string carNumber = "CA" + a + a + a + a + letters[letter1] + letters[letter2];
- CheckCarNumberForMagic(carNumber, weight);
- for (int b = 0; b <= 9 ; b++)
- {
- if (b != a)
- {
- CheckCarNumberForMagic("CA" + a + b + b + b + letters[letter1] + letters[letter2], weight);
- CheckCarNumberForMagic("CA" + a + a + a + b + letters[letter1] + letters[letter2], weight);
- CheckCarNumberForMagic("CA" + a + a + b + b + letters[letter1] + letters[letter2], weight);
- CheckCarNumberForMagic("CA" + a + b + a + b + letters[letter1] + letters[letter2], weight);
- CheckCarNumberForMagic("CA" + a + b + b + a + letters[letter1] + letters[letter2], weight);
- //"CAabbbXY", "CAaaabXY", "CAaabbXY", "CAababXY" and "CAabbaXY"
- }
- }
- }
- }
- }
- Console.WriteLine(count);
- }
- private static void CheckCarNumberForMagic(string carNumber, int weight)
- {
- int tempWeight = 0;
- foreach (var ch in carNumber)
- {
- if (ch >= '0' && ch <= '9')
- {
- tempWeight += ch - '0';
- }
- else
- {
- tempWeight += (ch - 64) * 10;
- }
- }
- if (tempWeight == weight)
- {
- count++;
- }
- }
- }
- 28 april ////////////////////////////////////////////////
- int targetWeight = int.Parse(Console.ReadLine());
- string[] cardFaces = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A" };
- string[] cardSuits = { "Clubs", "Diamonds", "Hearts", "Spades" };
- int count = 0;
- for (int face = 0; face < cardFaces.Length - 4; face++)
- {
- for (int suit1 = 0; suit1 < cardSuits.Length; suit1++)
- {
- for (int suit2 = 0; suit2 < cardSuits.Length; suit2++)
- {
- for (int suit3 = 0; suit3 < cardSuits.Length; suit3++)
- {
- for (int suit4 = 0; suit4 < cardSuits.Length; suit4++)
- {
- for (int suit5 = 0; suit5 < cardSuits.Length; suit5++)
- {
- int weight =
- (face + 1) * 10 + suit1 + 1 +
- (face + 2) * 20 + suit2 + 1 +
- (face + 3) * 30 + suit3 + 1 +
- (face + 4) * 40 + suit4 + 1 +
- (face + 5) * 50 + suit5 + 1;
- if (weight == targetWeight)
- {
- count++;
- // Print the straight hand + its weight
- //string card1 = cardFaces[face + 0] + cardSuits[suit1][0];
- //string card2 = cardFaces[face + 1] + cardSuits[suit2][0];
- //string card3 = cardFaces[face + 2] + cardSuits[suit3][0];
- //string card4 = cardFaces[face + 3] + cardSuits[suit4][0];
- //string card5 = cardFaces[face + 4] + cardSuits[suit5][0];
- //Console.WriteLine("({0} {1} {2} {3} {4}) -> weight {5}",
- // card1, card2, card3, card4, card5, weight);
- }
- }
- }
- }
- }
- }
- }
- Console.WriteLine(count);
- 26 AVGUST //////////////////////////////////////
- string input = Console.ReadLine();
- input = input.ToLower();
- int letSum = 0;
- bool hasWinningNumbers = false;
- for (int i = 0; i < input.Length; i++)
- {
- letSum += input[i] - 'a' + 1;
- }
- for (int i = 1; i < 10; i++)
- {
- for (int j = 1; j < 10; j++)
- {
- for (int k = 1; k < 10; k++)
- {
- for (int l = 1; l < 10; l++)
- {
- for (int m = 1; m < 10; m++)
- {
- for (int n = 1; n < 10; n++)
- {
- if (i * j * k == letSum && i * j * k == l * m * n)
- {
- Console.WriteLine("{0}{1}{2}-{3}{4}{5}",
- i, j, k, l, m, n);
- hasWinningNumbers = true;
- }
- }
- }
- }
- }
- }
- }
- if (!hasWinningNumbers)
- {
- Console.WriteLine("No");
- }
- //////////////// 25 july morning ////////////////////////////
- Dictionary<int, string> morseEncoding = new Dictionary<int, string>
- {
- {1, ".----"},
- {2, "..---"},
- {3, "...--"},
- {4, "....-"},
- {5, "....."}
- };
- int n = int.Parse(Console.ReadLine()); //1234
- int nSum = 0;
- bool hasAnwer = false;
- while (n != 0)
- {
- //Getting the current digit of the number
- int remainder = n % 10;
- //Summing up the digit to the total sum
- nSum += remainder;
- //Removing the last digit from the number
- n /= 10;
- }
- for (int i = 1; i <= 5; i++)
- {
- for (int j = 1; j <= 5; j++)
- {
- for (int k = 1; k <= 5; k++)
- {
- for (int l = 1; l <= 5; l++)
- {
- for (int m = 1; m <= 5; m++)
- {
- for (int o = 1; o <= 5; o++)
- {
- int product = i*j*k*l*m*o;
- if (product == nSum)
- {
- Console.WriteLine(morseEncoding[i] + '|' +
- morseEncoding[j] + '|' +
- morseEncoding[k] + '|' +
- morseEncoding[l] + '|' +
- morseEncoding[m] + '|' +
- morseEncoding[o] + '|');
- hasAnwer = true;
- }
- }
- }
- }
- }
- }
- }
- if(hasAnwer != true)
- Console.WriteLine("No");
- /////////////////////////////// 25 july evening //////////
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- string firstWord = Console.ReadLine();
- string secondWord = Console.ReadLine();
- int maxWeight = int.Parse(Console.ReadLine());
- bool resultFound = false;
- for (int firstDivider = 1; firstDivider < firstWord.Length; firstDivider++)
- {
- for (int secondDivider = 1; secondDivider < secondWord.Length; secondDivider++)
- {
- string firstLeft = firstWord.Substring(0, firstDivider);
- string firstRight = firstWord.Substring(firstDivider);
- string secondLeft = secondWord.Substring(0, secondDivider);
- string secondRight = secondWord.Substring(secondDivider);
- //Console.Write("{0}|{1}", firstLeft, firstRight);
- //Console.WriteLine(" {0}|{1}", secondLeft, secondRight);
- long sum = 0;
- for (int i = 0; i < firstLeft.Length; i++)
- {
- sum += (int)firstLeft[i];
- }
- long sum1 = 0;
- for (int i = 0; i < firstRight.Length; i++)
- {
- sum1 += (int)firstRight[i];
- }
- long sum2 = 0;
- for (int i = 0; i < secondLeft.Length; i++)
- {
- sum2 += (int)secondLeft[i];
- }
- long sum3 = 0;
- for (int i = 0; i < secondRight.Length; i++)
- {
- sum3 += (int)secondRight[i];
- }
- // long firstLeftWeight = CalculateWeight(firstLeft);
- // long firstRightWeight = CalculateWeight(firstRight);
- // long secondLeftWeight = CalculateWeight(secondLeft);
- // long secondRightWeight = CalculateWeight(secondRight);
- //Console.Write("{0}|{1}", firstLeftWeight, firstRightWeight);
- //Console.WriteLine(" {0}|{1}", secondLeftWeight, secondRightWeight);
- long nakovWeight = Math.Abs(
- sum * sum3 - sum1 * sum2);
- if (nakovWeight <= maxWeight)
- {
- resultFound = true;
- Console.WriteLine("({0}|{1}) matches ({2}|{3}) by {4} nakovs",
- firstLeft, firstRight, secondLeft, secondRight, nakovWeight);
- }
- }
- }
- if (!resultFound)
- {
- Console.WriteLine("No");
- }
- }
- static long CalculateWeight(string word)
- {
- long sum = 0;
- for (int i = 0; i < word.Length; i++)
- {
- sum += (int)word[i];
- }
- return sum;
- }
- }
- }
- /////////////// 22 avgust //////////////////
- int size =int.Parse(Console.ReadLine());
- int distance = int.Parse(Console.ReadLine());
- int counter = 0;
- for (int row = 1; row <= size; row++)
- {
- for (int column = 0; column <= size; column++)
- {
- //1
- if (column + distance + 1 <= size)
- {
- Console.WriteLine("{0} - {1}", "" + (char)(96 + row) + column
- , "" + (char)(96 + row) + (column + distance + 1));
- Console.WriteLine("{1} - {0}", "" + (char)(96 + row) + column
- , "" + (char)(96 + row) + (column + distance + 1));
- counter += 2;
- }
- //2
- if (row + distance + 1 <= size)
- {
- Console.WriteLine("{0} - {1}", "" + (char)(96 + row) + column
- , "" + (char)(96 + row + distance + 1) + column);
- Console.WriteLine("{1} - {0}", "" + (char)(96 + row) + column
- , "" + (char)(96 + row + distance + 1) + column);
- counter += 2;
- }
- //3
- if (row + distance + 1 <= size && column + distance + 1 <= size)
- {
- Console.WriteLine("{0} - {1}", "" + (char)(96 + row) + column
- , "" + (char)(96 + row + distance + 1) + (column + distance + 1));
- Console.WriteLine("{1} - {0}", "" + (char)(96 + row) + column
- , "" + (char)(96 + row + distance + 1) + (column + distance + 1));
- counter += 2;
- }
- //4
- if (row + distance + 1 <= size && column - distance - 1 > 0)
- {
- Console.WriteLine("{0} - {1}", "" + (char)(96 + row) + column
- , "" + (char)(96 + row + distance + 1) + (column - distance));
- Console.WriteLine("{1} - {0}", "" + (char)(96 + row) + column
- , "" + (char)(96 + row + distance + 1) + (column - distance));
- counter += 2;
- }
- }
- }
- if(counter == 0)
- {
- Console.WriteLine("No valid positions");
- }
- }
- //////////////////// 7 noemvri ////////////////////////
- string input = Console.ReadLine();
- int targetCount = int.Parse(Console.ReadLine());
- bool resultFound = false;
- int count = 0;
- for (int first = 0; first < input.Length; first++)
- {
- for (int second = 0; second < input.Length; second++)
- {
- for (int third = 0; third < input.Length; third++)
- {
- for (int fourth = 0; fourth < input.Length; fourth++)
- {
- for (int fifth = 0; fifth < input.Length; fifth++)
- {
- if (count == targetCount)
- {
- string output = "" + input[first] + input[second] + input[third]
- + input[fourth] + input[fifth];
- Console.WriteLine(output);
- resultFound = true;
- }
- count++;
- }
- }
- }
- }
- }
- if (!resultFound)
- {
- Console.WriteLine("No");
- }
- /////////////// 8 noemvri ///////////////////
- decimal cash = decimal.Parse(Console.ReadLine());
- string[] housesHand = Console.ReadLine().Split();
- int housesStrength = 0;
- foreach (var card in housesHand)
- {
- switch (card)
- {
- case "J": housesStrength += 11;
- break;
- case "Q": housesStrength += 12;
- break;
- case "K": housesStrength += 13;
- break;
- case "A": housesStrength += 14;
- break;
- default: housesStrength += int.Parse(card);
- break;
- }
- }
- int countWinning = 0;
- int totalHands = 0;
- for (int card1 = 2; card1 < 15; card1++)
- {
- for (int card2 = 2; card2 < 15; card2++)
- {
- for (int card3 = 2; card3 < 15; card3++)
- {
- for (int card4 = 2; card4 < 15; card4++)
- {
- int myPower = card1 + card2 + card3 + card4;
- if (myPower > housesStrength)
- {
- countWinning++;
- }
- totalHands++;
- }
- }
- }
- }
- decimal probability = (decimal)countWinning / totalHands;
- if (probability < 0.5m)
- {
- Console.WriteLine("FOLD");
- }
- else
- {
- Console.WriteLine("DRAW");
- }
- decimal expectedWinnings = probability * 2 * cash;
- Console.WriteLine("{0:f2}", expectedWinnings);
- }
- }
- //////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement