Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- izpit purvi zadachi ////////////////////////////////////////////////////////////////////////////
- 3 septemvri eggs ////////////////////////////////////////////////////////////////////////////
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- string lineContents = String.Empty;
- string[] eventTokens;
- string[] STRnumbers1;
- string kor = "";
- int hoi = 0;
- int sumEggs = 0;
- for (int i = 0; i < 7; i++)
- {
- lineContents = Console.ReadLine();
- eventTokens = lineContents.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- hoi = int.Parse(eventTokens[0]);
- kor = eventTokens[1];
- if (kor.Equals("eggs"))
- {
- sumEggs += hoi;
- }
- else if (kor.Equals("dozens"))
- {
- sumEggs += hoi * 12;
- }
- }
- int kondio = sumEggs / 12;
- int kila = sumEggs % 12;
- Console.WriteLine("{0} dozens + {1} eggs", kondio, kila);
- }
- }
- }
- 26 may Largest 3 Rectangles ////////////////////////////////////////////////////////////////
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] STRnumbers = Console.ReadLine().Split(new char[] { ' ','X','[',']','x' }, StringSplitOptions.RemoveEmptyEntries);
- int[] nums = Array.ConvertAll<string, int>(STRnumbers, int.Parse);
- List<int> listOfStrings = new List<int>();
- for (int i = 0; i < nums.Length; i += 2)
- {
- int hoi = nums[i] * nums[i + 1];
- listOfStrings.Add(hoi);
- }
- int sum = 0;
- int bestSum = 0;
- for (int i = 0; i < listOfStrings.Count-2; i++)
- {
- sum = 0;
- for (int j = i; j < 3 + i; j++)
- {
- sum += listOfStrings[j];
- }
- if (sum > bestSum)
- {
- bestSum = sum;
- }
- }
- Console.WriteLine(bestSum);
- }
- }
- }
- 3 septemvri bigest 3 prime numbers /////////////////////////////////////////////////////////////////////////
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- string[] inputTokens = input.Split(new char[] { ' ', '(', ')' }, StringSplitOptions.RemoveEmptyEntries);
- int[] numbers = inputTokens.Select(int.Parse).ToArray(); // converting string to int[];
- List<int> primes = new List<int>(); // Collecting prime numbers
- for (int i = 0; i < numbers.Length; i++)
- {
- if (isPrime(numbers[i]))
- {
- primes.Add(numbers[i]);
- }
- }
- primes.Sort();
- int index = 0;
- while (index < primes.Count - 1) // remove repeating numbers
- {
- if (primes[index] == primes[index + 1])
- primes.RemoveAt(index);
- else
- index++;
- }
- primes.Reverse();
- //foreach (var item in primes)
- //{
- // Console.WriteLine(item);
- //}
- for (int i = 0; i < primes.Count; i++)
- {
- if (primes.Count < 3)
- {
- Console.WriteLine("No");
- break;
- }
- else
- {
- Console.WriteLine(primes[0] + primes[1] + primes[2]);
- break;
- }
- }
- }
- public static bool isPrime(int number)
- {
- if ((number & 1) == 0)
- {
- if (number == 2)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- // Note:
- // ... This version was changed to test the square.
- // ... Original version tested against the square root.
- // ... Also we exclude 1 at the end.
- for (int i = 3; (i * i) <= number; i += 2)
- {
- if ((number % i) == 0)
- {
- return false;
- }
- }
- return number != 1;
- }
- }
- 1 zadacha simple expresion 1 june- java basic //////////////////////////////////////////////////////////////
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Collections;
- using System.Text.RegularExpressions;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- string text = Console.ReadLine();
- string regex = @"\+|\-";
- Queue separators = new Queue();
- Queue digits = new Queue();
- string[] wordsInSentence = Regex.Split(text, regex);
- foreach (var w in wordsInSentence)
- {
- digits.Enqueue(w.Trim());
- }
- MatchCollection separatorsInSentance = Regex.Matches(text, regex);
- foreach (var s in separatorsInSentance)
- {
- separators.Enqueue(s);
- }
- StringBuilder reversSentance = new StringBuilder();
- while (digits.Count > 0 || separators.Count > 0)
- {
- reversSentance.Append(digits.Dequeue());
- if (digits.Count == 0)
- {
- continue;
- }
- reversSentance.Append(" ");
- reversSentance.Append(separators.Dequeue());
- }
- string builder = reversSentance.ToString();
- string[] STRnumbers = builder.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- /////////////////////////////////////////////////// 1 ot variantite
- // int[] array = new int[STRnumbers.Length];
- // decimal[] array = Array.ConvertAll<string, decimal>(STRnumbers, decimal.Parse);
- // decimal sum = array.Sum();
- // Console.WriteLine("{0:F9}",sum);
- ///////////////////////////////////////// 2 variant
- List<string> hoi = new List<string>();
- for (int i = 0; i < STRnumbers.Length; i++)
- {
- hoi.Add(STRnumbers[i]);
- }
- decimal total = hoi.Sum(x => Convert.ToDecimal(x));
- Console.WriteLine("{0:F9}",total);
- }
- }
- }
- Problem 4 – Couples Frequency
- using System;
- using System.Collections.Generic;
- using System.Linq;
- public class CouplesFrequency
- {
- public static void Main()
- {
- int[] numbers = Console.ReadLine()
- .Split()
- .Select(int.Parse)
- .ToArray();
- int totalNumberOfCouples = numbers.Length - 1;
- var coupleFrequencies = new Dictionary<string, int>();
- for (int i = 1; i < numbers.Length; i++)
- {
- string currentCouple = string.Format(
- "{0} {1}",
- numbers[i - 1],
- numbers[i]);
- if (!coupleFrequencies.ContainsKey(currentCouple))
- {
- coupleFrequencies.Add(currentCouple, 0);
- }
- coupleFrequencies[currentCouple]++;
- }
- foreach (var coupleFrequency in coupleFrequencies)
- {
- double frequency = coupleFrequency.Value * 100.0 / totalNumberOfCouples;
- Console.WriteLine(
- "{0} -> {1:F2}%",
- coupleFrequency.Key,
- frequency);
- }
- }
- }
- Problem 11 – Little John ///////////////////////////////////////////////////////////////////////////
- 2 moe reshenie dava 62 to4ki
- using System;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Collections.Generic;
- public class LittleJohn
- {
- public static void Main()
- {
- StringBuilder sb = new StringBuilder();
- //for (int i = 0; i < 4; i++)
- //{
- // sb.AppendFormat(" {0}", Console.ReadLine());
- //}
- string STRnumbers = @">>>----->>abc>>>----->>
- >>>----->>
- >----->sdhdkiiiyyyyyyyyy>>>--->>>
- >>----->";
- const string ArrowPattern = @"[^->]((.\s)*?)";
- string[] wordsInSentence = Regex.Split(STRnumbers, ArrowPattern);
- List<string> listOfStrings = new List<string>();
- foreach (var w in wordsInSentence)
- {
- if (w != "")
- {
- listOfStrings.Add(w);
- }
- }
- Regex arrowMatcher = new Regex(ArrowPattern);
- var arrows = arrowMatcher.Matches(sb.ToString());
- byte largeArrowCount = 0;
- byte mediumArrowCount = 0;
- byte smallArrowCount = 0;
- for (int i = 0; i < listOfStrings.Count ; i++)
- {
- if (listOfStrings[i].Equals(">>>----->>"))
- {
- largeArrowCount++;
- }
- else if (listOfStrings[i].Equals(">>----->"))
- {
- mediumArrowCount++;
- }
- else if (listOfStrings[i].Equals(">----->"))
- {
- smallArrowCount++;
- }
- }
- //foreach (Match arrow in arrows)
- //{
- // if (!string.IsNullOrEmpty(arrow.Groups[1].Value))
- // {
- // largeArrowCount++;
- // }
- // else if (!string.IsNullOrEmpty(arrow.Groups[2].Value))
- // {
- // mediumArrowCount++;
- // }
- // else
- // {
- // smallArrowCount++;
- // }
- //}
- string numberAsString = string.Format(
- "{0}{1}{2}",
- smallArrowCount,
- mediumArrowCount,
- largeArrowCount);
- short number = short.Parse(numberAsString);
- string binaryNum = Convert.ToString(number, 2);
- string reversedBinaryNum = new string(binaryNum.Reverse().ToArray());
- string resultAsString = binaryNum + reversedBinaryNum;
- short result = Convert.ToInt16(resultAsString, 2);
- Console.WriteLine(result);
- }
- }
- 2 reshenie za 100 to4ki //////////////////////////////////////////////////////////////////////////////
- using System;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- public class LittleJohn
- {
- public static void Main()
- {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < 4; i++)
- {
- sb.AppendFormat(" {0}", Console.ReadLine());
- }
- const string ArrowPattern = @"(>>>----->>)|(>>----->)|(>----->)";
- Regex arrowMatcher = new Regex(ArrowPattern);
- var arrows = arrowMatcher.Matches(sb.ToString());
- int largeArrowCount = 0;
- int mediumArrowCount = 0;
- int smallArrowCount = 0;
- foreach (Match arrow in arrows)
- {
- if (!string.IsNullOrEmpty(arrow.Groups[1].Value))
- {
- largeArrowCount++;
- }
- else if (!string.IsNullOrEmpty(arrow.Groups[2].Value))
- {
- mediumArrowCount++;
- }
- else if (!string.IsNullOrEmpty(arrow.Groups[3].Value))
- {
- smallArrowCount++;
- }
- }
- string numberAsString = string.Format(
- "{0}{1}{2}",
- smallArrowCount,
- mediumArrowCount,
- largeArrowCount);
- short number = short.Parse(numberAsString);
- string binaryNum = Convert.ToString(number, 2);
- string reversedBinaryNum = new string(binaryNum.Reverse().ToArray());
- string resultAsString = binaryNum + reversedBinaryNum;
- short result = Convert.ToInt16(resultAsString, 2);
- Console.WriteLine(result);
- }
- }
- 15 zadacha Upper Words ////////////////////////////////////////////////////////////////////////////
- using System;
- using System.Text.RegularExpressions;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace UppercaseWords
- {
- class UppercaseWords
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- string pattern = @"([a-zA-Z]+)|(\s|\W+|(\d+))*";
- Regex word = new Regex(pattern);
- while (input != "END")
- {
- MatchCollection words = word.Matches(input);
- StringBuilder result = new StringBuilder();
- foreach (var item in words)
- {
- string forAppend = item.ToString();
- if (IsUpper(forAppend))
- {
- if (IsPalindrome(forAppend))
- {
- forAppend = DoubleEachLetters(forAppend);
- }
- else
- {
- forAppend = Reverse(forAppend);
- }
- }
- result.Append(forAppend);
- }
- Console.WriteLine(EscapeXmlString(result.ToString()));
- input = Console.ReadLine();
- }
- }
- public static bool IsUpper(string input)
- {
- for (int i = 0; i < input.Length; i++)
- {
- if (!Char.IsUpper(input[i]))
- return false;
- }
- return true;
- }
- public static string EscapeXmlString(string value)
- {
- return System.Security.SecurityElement.Escape(value);
- }
- public static string Reverse(string s)
- {
- char[] charArray = s.ToCharArray();
- Array.Reverse(charArray);
- return new string(charArray);
- }
- private static string DoubleEachLetters(string forAppend)
- {
- StringBuilder doubledString = new StringBuilder();
- for (int i = 0; i < forAppend.Length; i++)
- {
- char letter = forAppend[i];
- doubledString.Append(letter);
- doubledString.Append(letter);
- }
- return doubledString.ToString();
- }
- public static bool IsPalindrome(string value)
- {
- string[] a = value.Select(c => c.ToString()).ToArray();
- bool isSymmetric = true;
- for (int i = 0; i <a.Length / 2; i++)// na purvoto zavurtane na cikula size = 5 i za tova 5 - 0 - 1 = 4 index koito mi e 1 v slu4aq
- { // pri vtoroto zavurtane mi vzima 1 i 3 element i taka natatuk
- if (a[i] != a[a.Length - i - 1])
- {
- isSymmetric = false;
- break;
- }
- }
- return isSymmetric;
- }
- }
- }
- 18 zadacha Pin Validation ///////////////////////////////////////////////////////////////
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace PinValidation
- {
- class PinValidation
- {
- static void Main(string[] args)
- {
- string name = Console.ReadLine();
- string gender = Console.ReadLine();
- string egn = Console.ReadLine();
- int[] egnDigits = new int[egn.Length];
- bool isEgnMadeOfDigits = true;
- for (int i = 0; i < egn.Length; i++)
- {
- int nextDigit;
- isEgnMadeOfDigits = int.TryParse(egn[i].ToString(), out nextDigit);
- if (!isEgnMadeOfDigits)
- {
- break;
- }
- egnDigits[i] = nextDigit;
- }
- if (!isEgnMadeOfDigits)
- {
- Console.WriteLine("<h2>Incorrect data</h2>");
- return;
- }
- bool isLegthCorrect = egn.Length == 10;
- bool isGenderCorrect = (gender == "male" && egnDigits[8] % 2 == 0) || (gender == "female" && egnDigits[8] % 2 == 1);
- int year = int.Parse(egn.Substring(0, 2));
- int month = int.Parse(egn.Substring(2, 2));
- int day = int.Parse(egn.Substring(4, 2));
- if (month > 20 && month <= 32)
- {
- month -= 20;
- year = 1800 + year;
- }
- else if (month > 40 && month <= 52)
- {
- month -= 40;
- year = 2000 + year;
- }
- else
- {
- year = 1900 + year;
- }
- DateTime date = new DateTime();
- bool isDateCorrect = DateTime.TryParse(String.Format("{0}.{1}.{2}", month, day, year), out date);
- int checkSum = (egnDigits[0] * 2 + egnDigits[1] * 4 + egnDigits[2] * 8 + egnDigits[3] * 5 + egnDigits[4] * 10 + egnDigits[5] * 9
- + egnDigits[6] * 7 + egnDigits[7] * 3 + egnDigits[8] * 6) % 11;
- if (checkSum == 10)
- {
- checkSum = 0;
- }
- bool isCheckSumCorrect = (checkSum == egnDigits[9]);
- if (isLegthCorrect && isGenderCorrect && isDateCorrect && isCheckSumCorrect)
- {
- Console.WriteLine("{{\"name\":\"{0}\",\"gender\":\"{1}\",\"pin\":\"{2}\"}}", name, gender, egn);
- }
- else
- {
- Console.WriteLine("<h2>Incorrect data</h2>");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment