Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Text;
- namespace Example
- {
- class MyApplication
- {
- static void CeasarEncode(string input, int shift)
- {
- StringBuilder encoded = new StringBuilder(input);
- for (int i = 0; i < encoded.Length; i++)
- encoded[i] += Convert.ToChar(shift);
- Console.WriteLine(encoded);
- Console.ReadKey();
- Console.Clear();
- }
- static void CeasarDecode(string input, int shift)
- {
- StringBuilder encoded = new StringBuilder(input);
- for (int i = 0; i < encoded.Length; i++)
- encoded[i] -= Convert.ToChar(shift);
- Console.WriteLine(encoded);
- Console.ReadKey();
- Console.Clear();
- }
- static void MatrixMult(double[,] matrix, double value)
- {
- for (int i = 0; i < matrix.GetLength(0); i++)
- {
- for (int j = 0; j < matrix.GetLength(1); j++)
- {
- matrix[i, j] *= value;
- Console.Write("{0:F2} ", matrix[i, j]);
- }
- Console.WriteLine();
- }
- Console.ReadKey();
- Console.Clear();
- }
- static void MatrixMult(double[,] first, double[,] second)
- {
- if (first.GetLength(0) == second.GetLength(1) && first.GetLength(1) == second.GetLength(0))
- {
- int maxCoulmn = Math.Max(first.GetLength(0), second.GetLength(0));
- int maxRows = Math.Max(first.GetLength(1), second.GetLength(1));
- double[,] result = new double[maxCoulmn, maxRows];
- for (int i = 0; i < maxCoulmn; i++)
- {
- for (int m = 0; m < first.GetLength(1); m++)
- {
- double sum = 0;
- for (int k = 0; k < first.GetLength(1); k++)
- {
- sum += first[i, k] * second[k, m];
- }
- result[i, m] = sum;
- Console.Write($"{result[i, m]} ");
- }
- Console.WriteLine();
- }
- }
- else
- {
- Console.WriteLine("Неверный формат.");
- }
- Console.ReadKey();
- Console.Clear();
- }
- static void SumMatrix(double[,] first, double[,] second)
- {
- if (first.GetLength(0) == second.GetLength(0) && first.GetLength(1) == second.GetLength(1))
- {
- double[,] result = new double[first.GetLength(0), first.GetLength(1)];
- for (int i = 0; i < result.GetLength(0); i++)
- {
- for (int j = 0; j < result.GetLength(1); j++)
- {
- result[i, j] = first[i, j] + second[i, j];
- Console.Write("{0} ", result[i, j]);
- }
- Console.WriteLine();
- }
- }
- else
- {
- Console.WriteLine("Неверный формат.");
- }
- }
- static void CalcString(string input)
- {
- char[] operations = { '+', '-' };
- int operandShift = 1;
- string[] operands = input.Split(new char[] { '+', '-' });
- double result = double.Parse(operands[0]);
- while (true)
- {
- int index = input.IndexOfAny(operations);
- if (index == -1)
- break;
- if (input[index] == '+')
- result += double.Parse(operands[operandShift]);
- else if (input[index] == '-')
- result -= double.Parse(operands[operandShift]);
- operandShift++;
- input = input.Remove(0, index + 1);
- }
- Console.WriteLine($"{result}");
- Console.ReadKey();
- Console.Clear();
- }
- static void UpperSentenceBeginning(string text)
- {
- string[] split = text.Split(new char[] { '.' }, StringSplitOptions.TrimEntries);
- Console.WriteLine(string.Join(". ", split.Select(s => s[0].ToString().ToUpper() + s.Substring(1))));
- Console.ReadKey();
- Console.Clear();
- }
- static void CensorString(string text, params string[] badWords)
- {
- foreach (var item in badWords)
- {
- int counter = 0;
- int startIndex = -1;
- while ((startIndex = (text.IndexOf(item, startIndex + 1))) != -1)
- counter++;
- text = text.Replace(item, new string(Enumerable.Repeat('*', item.Length).ToArray()));
- Console.WriteLine($"{item} - {counter}");
- }
- Console.WriteLine(text);
- Console.ReadKey();
- Console.Clear();
- }
- public static void Main()
- {
- CeasarEncode("Я люблю свою маму", 3);
- CeasarDecode("в#оёдоё#фесё#пгпц", 3);
- MatrixMult(new double[,] { { 1, 2, 3, 4, 5 }, { 2, 3, 4, 5, 6 } }, 2.4);
- SumMatrix(new double[,] { { 1, 2, 3, 4, 5 }, { 2, 3, 4, 5, 6 } }, new double[,] { { 1, 2, 3, 4, 5 }, { 2, 3, 4, 5, 6 } });
- MatrixMult(new double[,] { { 0, -1, 1 }, { 3, 2, 2 }, { 1, 0, -2 } }, new double[,] { { 0, -1, 1 }, { 3, 2, 2 }, { 1, 0, -2 } });
- CalcString("1 + 2 + 4 + 3 - 220");
- UpperSentenceBeginning("today is a good day for walking. i will try to walk near the sea");
- CensorString(@"To be, or not to be, that is the question,
- Whether 'tis nobler in the mind to suffer
- The slings and arrows of outrageous fortune,
- Or to take arms against a sea of troubles,
- And by opposing end them? To die: to sleep;
- No more; and by a sleep to say we end
- The heart-ache and the thousand natural shocks
- That flesh is heir to, 'tis a consummation
- Devoutly to be wish'd. To die, to sleep", "die", "fortune");
- }
- }
- }
Add Comment
Please, Sign In to add comment