Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace _2._7._2018_KSI
- {
- using System;
- using System.Globalization;
- using System.Threading;
- class Resource
- {
- public string Code { get; set; }
- public string Name { get; set; }
- public double Volume { get; set; }
- public int ExpirationDays { get; set; }
- public char Group { get; set; }
- public DateTime EntryDate { get; set; }
- public string Position { get; set; }
- public int? Humidity { get; set; }
- }
- class Program
- {
- static void Main()
- {
- // 1. Entering N
- uint N = EnterNumberN();
- // 2. Creating the collection of resources
- Resource[] resources = new Resource[N];
- // 3. Entering the resources
- EnterData(resources);
- // 4. Output the elements
- OutputElements(resources);
- }
- static uint EnterNumberN()
- {
- uint N = 0;
- bool isInt = false;
- do
- {
- Console.Write("Please, enter an integer positive number between 0 and 10000 of the resources N = ");
- isInt = uint.TryParse(Console.ReadLine(), out N);
- } while (N < 0 || !isInt || N > 10000);
- return N;
- }
- static void EnterData(Resource[] resources)
- {
- for (int i = 0; i < resources.Length; i++)
- {
- Resource resource = new Resource();
- Console.WriteLine("------------ Resource number {0} -------", i);
- Console.Write("Please, enter the Code up to 4 characters: ");
- resource.Code = Console.ReadLine();
- Console.Write("Please, enter the Name up to 55 characters: ");
- resource.Name = Console.ReadLine();
- Console.Write("Please, enter the Volume real number 2 digits after the decimal point: ");
- resource.Volume = double.Parse(Console.ReadLine());
- Console.Write("Expiration days positive integer number: ");
- resource.ExpirationDays = int.Parse(Console.ReadLine());
- Console.Write("Please enter a group 'E' - special or 'S' - normal: ");
- resource.Group = Console.ReadLine()[0];
- Console.Write("Please, enter the entry date (dd.mm.yyyy): ");
- resource.EntryDate = DateTime.Parse(Console.ReadLine());
- Console.Write("Please, enter the position in the storage (up to 10 characters): ");
- resource.Position = Console.ReadLine();
- if (resource.Group == 'E')
- {
- Console.Write("Please, enter the humidity positive integer number: ");
- resource.Humidity = int.Parse(Console.ReadLine());
- }
- resources[i] = resource;
- }
- }
- static void OutputElements(Resource[] resources)
- {
- Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); //CultureInfo.InvariantCulture;
- for (int i = 0; i < resources.Length; i++)
- {
- if (resources[i].Group == 'E')
- {
- Console.WriteLine("{0}, {1}, {2}, {3:F2}, {4:dd.MM.yyyy}, {5}, В%={6:F2}",
- resources[i].Position,
- resources[i].Code,
- resources[i].Name,
- resources[i].Volume,
- resources[i].EntryDate,
- resources[i].ExpirationDays,
- resources[i].Humidity
- );
- }
- else
- {
- Console.WriteLine("{0}, {1}, {2}, {3:F2}, {4:dd.MM.yyyy}, {5}",
- resources[i].Position,
- resources[i].Code,
- resources[i].Name,
- resources[i].Volume,
- resources[i].EntryDate,
- resources[i].ExpirationDays
- );
- }
- }
- }
- }
- }
- // Включваме простраството от имена System
- using System;
- // Клас за дефиниране на обeкти
- class Employeesregister
- {
- public string Name { get; set; }
- public string EGN { get; set; }
- public string NamewithLatinletters { get; set; }
- public string Domicile { get; set; }
- public string CyrrilycName { get; set; } //?
- public string FirstName { get; set; } //?
- public string SurName { get; set; } //?
- public string FamilyName { get; set; } //?
- }
- // Kлас с програмата
- class Program
- {
- // Основен метод на програмата. Входна точка.
- static void Main()
- { // 1. Въвеждаме броя на служителите
- uint N = EnterNumberN();
- Employeesregister[] datas = new Employeesregister[N];
- // 2. Извикване на метод за въвеждане на данните на служителите
- InputData(datas);
- // 3. Извикваме метода за сортировка на служителите по държава, а тези които са от една и съща държава-сортирани по азбучен ред на името
- SortByCountryAndName(datas);
- // Извикваме метода за извеждане нa служителите
- OutputData(datas);
- // Да се изведе списък със служителите, за които не са въведени задължителните полета.Списъкът да е
- //сортиран по ЕГН
- // 4. Извикваме метода за филтриране на служителите, които не са въвели задължителните полета
- Employeesregister[] filteredByunfilledBoxes = FilterByUnfilledBoxes(datas);
- // 5. Извикваме метода за сортировка на служителите по ЕГН , които не са въвели задължителните полета
- SortByEGN(filteredByunfilledBoxes);
- // 6. Извикваме метода за извеждане на служителите
- OutputData(filteredByunfilledBoxes);
- // За всеки един от служителите трябва да се генерира име на служебна поща по
- // следния начин(данните извличаме от името с латински букви, ако не е празно):
- // ‹Фамилия›_‹Име›_‹Първата буква от бащиното име›@nncomputers.com.
- //Ако в името на английски липсват бащино, или първо и бащино име, те се пропускат
- //при генерирането на пощата.Да се изведе списък с имената на новите служители и
- //пощата, за които името на пощата е генерирано успешно. За примера в точка две
- //резултатът ще бъде:
- //Иван Петров Иванов, email: Ivanov_Ivan @nncomputers.com
- // 7. Извикваме метода за филтриране на служителите, които са въвели име с латински букви
- Employeesregister[] filteredByEmail = FilterByEmail(datas);
- // Извикваме метода за извеждане на служителите
- OutputPost(filteredByEmail);
- // 8. Извикваме метода за извеждане на служебна поща на служителите
- OutputPost(datas);
- }
- //1. Въвеждаме броя на служителите
- static uint EnterNumberN()
- {
- Console.Write("Please enter the number of employees: ");
- uint N = uint.Parse(Console.ReadLine());
- return N;
- }
- //2. Дeфиниране на метода за въвеждане на данните на служителите
- static void InputData(Employeesregister[] datas)
- {
- for (int i = 0; i < datas.Length; i++)
- {
- Employeesregister data = new Employeesregister();
- Console.WriteLine("------------ Employee number {0} -------", i);
- Console.Write("Please enter the name of the operator up to 50 characters :");
- data.Name = Console.ReadLine();
- Console.Write("Please enter EGN up to 15 characters: ");
- data.EGN = Console.ReadLine();
- Console.Write("Please enter a name with Latin letters up to 50 characters :");
- data.NamewithLatinletters = Console.ReadLine();
- Console.Write("Please enter a domicile ( a country, a postal code, a city-strings up to 30 characters) :");
- data.Domicile = Console.ReadLine();
- // добавяме служителя в масива
- datas[i] = data;
- }
- }
- //3. Дефинираме метод за сортиране на служителите (по метода на мехурчето) по държава, а тези които са от една и съща държава-сортирани по азбучен ред на името
- static void SortByCountryAndName(Employeesregister[] datas)
- {
- Employeesregister swap;
- for (int i = 0; i < datas.Length; i++)
- {
- if (datas[i] == default(Employeesregister)) continue;
- {
- for (int j = i + 1; j < datas.Length; j++)
- {
- if (datas[j] == default(Employeesregister)) continue;
- {
- if (string.Compare(datas[i].Domicile, datas[j].Domicile) > 0)
- {
- swap = datas[i];
- datas[i] = datas[j];
- datas[j] = swap;
- }
- if (string.Compare(datas[i].Domicile, datas[j].Domicile) == 0)
- {
- if (string.Compare(datas[i].Name, datas[j].Name) > 0)
- {
- swap = datas[i];
- datas[i] = datas[j];
- datas[j] = swap;
- }
- }
- }
- }
- }
- }
- }
- //4. Дефиниране на метод за филтриране на служителите, които не са въвели задължителните полета
- static Employeesregister[] FilterByUnfilledBoxes(Employeesregister[] datas)
- {
- Employeesregister[] filteredByunfilledBoxes = new Employeesregister[datas.Length];
- Employeesregister data = new Employeesregister();
- for (int i = 0; i < datas.Length; i++)
- {
- if (data.Name == null)
- {
- filteredByunfilledBoxes[i] = datas[i];
- }
- if (data.EGN == null)
- {
- filteredByunfilledBoxes[i] = datas[i];
- }
- if (data.NamewithLatinletters == null)
- {
- filteredByunfilledBoxes[i] = datas[i];
- }
- if (data.Domicile == null)
- {
- filteredByunfilledBoxes[i] = datas[i];
- }
- }
- return filteredByunfilledBoxes;
- }
- //5. Дефинираме метода за сортировка на служителите по ЕГН , които не са въвели задължителните полета
- static void SortByEGN(Employeesregister[] datas)
- {
- Employeesregister temp;
- for (int i = 0; i < datas.Length; i++)
- {
- for (int j = i + 1; j < datas.Length; j++)
- {
- if (String.Compare(datas[i].EGN, datas[j].EGN) > 0)
- {
- temp = datas[i];
- datas[i] = datas[j];
- datas[j] = temp;
- }
- }
- }
- }
- //6. Дефиниране на метода за извеждане на служителите
- static void OutputData(Employeesregister[] data)
- {
- for (int i = 0; i < data.Length; i++)
- {
- Console.WriteLine("{0}, {1}, {2}, {3} ",
- data[i].Name,
- data[i].EGN,
- data[i].NamewithLatinletters,
- data[i].Domicile
- );
- }
- }
- // 7. Дефиниране на метода за въвеждане
- static void InputPost(Employeesregister[] datas)
- {
- for (int i = 0; i < datas.Length; i++)
- {
- Employeesregister data = new Employeesregister();
- if (datas[i].NamewithLatinletters != null)
- {
- Console.Write("Please enter CyrrilycName :");
- data.CyrrilycName = Console.ReadLine();
- Console.Write("Please enter first name :");
- data.FirstName = Console.ReadLine();
- Console.Write("Please enter surname :");
- data.SurName = Console.ReadLine();
- Console.Write("Please enter family name :");
- data.FamilyName = Console.ReadLine();
- }
- datas[i] = data;
- }
- //7. Дефинираме метода за филтриране на служителите, които са въвели име с латински букви
- static Employeesregister[] FilterByEmail(Employeesregister[] datas)
- {
- Employeesregister[] filteredByEmail = new Employeesregister[datas.Length];
- for (int i = 0; i < datas.Length; i++)
- {
- if (datas[i].NamewithLatinletters != null)
- {
- filteredByEmail[i] = datas[i];
- }
- }
- return filteredByEmail;
- }
- //8. Дефиниране на метода за извеждане на служебна поща на служителите
- static void OutputPost(Employeesregister[] datas)
- {
- for (int i = 0; i < datas.Length; i++)
- {
- if (datas[i].SurName != null)
- if (datas[i].FirstName !=null)
- {
- Console.WriteLine("{0}, email: {1}_{2}@nncomputers.com",
- datas[i].CyrrilycName,
- datas[i].FamilyName,
- datas[i].FirstName
- );
- }
- }
- }
- }
- // Включваме простраството от имена System
- using System;
- // Клас за дефиниране на обeкти
- class Discount
- {
- public string Name { get; set; }
- public string City { get; set; }
- public string Code { get; set; }
- //public int CategoryofGoods { get; set; }
- //public int DiscountCode { get; set; }
- //public string Percent { get; set; }
- //public DateTime Date { get; set; }
- }
- // Kлас с програмата
- class Program
- {
- // Основен метод на програмата. Входна точка.
- static void Main()
- {
- // 1. Въвеждаме броя на клиентите
- uint N = EnterNumberN();
- Discount[] discounts = new Discount[N];
- //2. Извикване на метод за въвеждане на клиентите
- InputData(discounts);
- //3. Извикваме метода за сортировка на имената на клиентите по азбучен ред
- SortByName(discounts);
- //4. Извикваме метода за извеждане на клиентите
- OutputData(discounts);
- // Да се изведе списък на клиентите от Пловдив с карта за отстъпки на козметика.
- // Изведената информация за клиент да бъде във формата от условие 2.Списъкът да се
- //подреди в нарастващ ред по процентна отстъпка, а при еднаква стойност клиентите да
- //бъдат подредени по име в азбучен ред.
- //Да се изведе списък на клиентите от Пловдив с карта за отстъпки на козметика.
- //5. Филтрираме клиентите от Пловдив с карта за отстъпки на козметика
- Discount[] filteredByCityAndCategory = FilterByCityAndCategory(discounts);
- // Списъкът да се
- //подреди в нарастващ ред по процентна отстъпка, а при еднаква стойност клиентите да
- //бъдат подредени по име в азбучен ред.
- //6. Извикваме метода за сортировка на списъка в нарастващ ред по процентна отстъпка, а при еднаква стойност клиентите са подредени
- // по име в азбучен ред.
- SortByPercentDiscoundAndName(filteredByCityAndCategory);
- //Изведената информация за клиент да бъде във формата от условие 2.
- OutputData(filteredByCityAndCategory);
- ////Изведената информация за клиент да бъде във формата от условие 2.
- //OutputData(filteredByCityAndCategory);
- // Да се въведе категория на стока (например 2). Да се намери и изведе
- //максималният процент на отстъпка за въведената категория
- //7. Намира и извежда максимал ният процент на отстъпка за въведената категория
- Console.WriteLine("Mаксимален процент на отстъпка за въведената категория= {0}", MaxProcent(discounts));
- //FindMaxByCode(Discount[] discounts, code);
- }
- //1. Въвеждаме броя на клиентите
- static uint EnterNumberN()
- {
- Console.Write("Please enter a number of employees [1;500] : ");
- uint N = uint.Parse(Console.ReadLine());
- return N;
- }
- //2. Дeфиниция на метода за въвеждане на клиентите
- static void InputData(Discount[] discounts)
- {
- for (int i = 0; i < discounts.Length; i++)
- {
- Discount discount = new Discount();
- Console.Write("Please, enter first and family name: ");
- discount.Name = Console.ReadLine();
- Console.Write("Please, enter a city of residence: ");
- discount.City = Console.ReadLine();
- Console.Write("Please, enter category of goods (1– козметика, 2 – парфюми, 3 – аксесоари, 4 – услуги) :");
- discount.Code = Console.ReadLine();
- Console.Write("Please enter a code for discounts (0 – без натрупване, 1 – с натрупване) :");
- discount.Code = Console.ReadLine();
- Console.Write("Please enter a percent of discount 05, 10, 20 или 30: ");
- discount.Code = Console.ReadLine();
- Console.Write("Please, enter the day of issue of card : ");
- discount.Code = Console.ReadLine();
- Console.Write("Please, enter the month of issue of card : ");
- discount.Code = Console.ReadLine();
- Console.Write("Please, enter the year of issue of card : ");
- discount.Code = Console.ReadLine();
- //Console.Write("Please, enter a category of goods: 1-козметика, 2 – парфюми, 3 – аксесоари, 4 – услуги");
- //resource.TenDigitCode = Console.ReadLine();
- //Console.Write("Please, enter a code for discount: 0 – без натрупване, 1 – с натрупване");
- //resource.TenDigitCode = Console.ReadLine();
- //Console.Write("Please, enter a percent of the discount : 05, 10, 20 или 30");
- //resource.TenDigitCode = Console.ReadLine();
- //Console.Write("Please, enter two digits for day(..) for month (..) and for year (..) of issue of the card (for example-05/06/17) ");
- //resource.TenDigitCode = Console.ReadLine();
- // добавяме ресурса в масива
- discounts[i] = discount;
- }
- }
- //3. Дефинираме метода за сортировка на имената на клиентите по азбучен ред
- static void SortByName(Discount[] discounts)
- {
- Discount temp;
- for (int i = 0; i < discounts.Length; i++)
- {
- for (int j = i + 1; j < discounts.Length; j++)
- {
- if (String.Compare(discounts[i].Name, discounts[j].Name) > 0)
- {
- temp = discounts[i];
- discounts[i] = discounts[j];
- discounts[j] = temp;
- }
- }
- }
- }
- //4. Дефинираме метода за извеждане на клиентите
- static void OutputData(Discount[] discounts)
- { //discount.TenDigitCode
- //Discount discount = new Discount();
- for (int i = 0; i < discounts.Length; i++)
- {
- string firstDigit = discounts[i].Code.Substring(0,1);
- string secondDigit = discounts[i].Code.Substring(1,1);
- string thirdDigit = discounts[i].Code.Substring(2,2);
- string fourthDigit = discounts[i].Code.Substring(4,2);
- string fifthDigit = discounts[i].Code.Substring(6,2);
- string sixthDigit = discounts[i].Code.Substring(8,2);
- string category = "";
- //string firstDigit
- switch (discounts[i].Code.Substring(0, 1)) // null?
- //switch (discounts[i].category)
- {
- case "1":
- category = "козметика";
- break;
- case "2":
- category = "парфюми";
- break;
- case "3":
- category = "аксесоари";
- break;
- case "4":
- category = " услуги";
- break;
- default:
- break;
- }
- string discountCode = "";
- switch (discounts[i].Code.Substring(1,1))
- {
- case "1":
- discountCode = " без натрупване";
- break;
- case "2":
- discountCode = "с натрупване";
- break;
- default:
- break;
- }
- //string percent = discounts[i].TenDigitCode.Substring(2, 2)
- //switch (discounts[i].TenDigitCode.Substring(2, 2))
- //{
- // string Day = "";
- //switch (discounts[i].TenDigitCode.Substring(3, 2))
- string day = discounts[i].Code.Substring(4, 2);
- string month = discounts[i].Code.Substring(6, 2);
- string year = discounts[i].Code.Substring(8, 2);
- Console.WriteLine(" {0}, {1}, {2},{3} {4}.{5}.{6}",
- discounts[i].Name,
- discounts[i].City,
- category, discountCode, day, month, year);
- }
- //Console.WriteLine("{0}, {1}, {2}, {3}, {4}, {5} ",
- // discounts[i].Name,
- // discounts[i].City,
- // categoryofGoods,
- // discountCode,
- // discounts[i].Percent,
- // discounts[i].Date
- // );
- //}
- }
- // 5. Дефиниране на метод за филтриране на елементите от Пловдив с карта за отстъпки за козметика(категория стоки-1 козметика)
- static Discount[] FilterByCityAndCategory(Discount[] discounts)
- {
- Discount[] filteredByByCityAndCategory = new Discount[discounts.Length];
- for (int i = 0; i < discounts.Length; i++)
- {
- if (discounts[i].City == "Пловдив")
- if (discounts[i].Code.Substring(0, 1) == "1") //"козметика"
- {
- filteredByByCityAndCategory[i] = discounts[i];
- }
- }
- return filteredByByCityAndCategory;
- }
- //6. Дефиниране на метода за сортировка на списъка в нарастващ ред по процентна отстъпка, а при еднаква стойност клиентите са подредени
- // по име в азбучен ред.
- static void SortByPercentDiscoundAndName(Discount[] discounts)
- {
- Discount swap;
- for (int i = 0; i < discounts.Length; i++)
- {
- for (int j = i + 1; j < discounts.Length; j++)
- {
- if (String.Compare(discounts[i].Code.Substring(2, 2), discounts[j].Code.Substring(2, 2)) > 0) // System.NullReferenceException: 'Object reference not set to an instance of an object.'
- //discounts[] was null.
- {
- swap = discounts[i];
- discounts[i] = discounts[j];
- discounts[j] = swap;
- }
- if (String.Compare(discounts[i].Code.Substring(2, 2), discounts[j].Code.Substring(2, 2)) == 0)
- {
- if (String.Compare(discounts[i].Name, discounts[j].Name) > 0)
- {
- swap = discounts[i];
- discounts[i] = discounts[j];
- discounts[j] = swap;
- }
- }
- }
- }
- }
- // 7. Дефинираме метода за намиране максималният процент на отстъпка за въведената категория
- static string MaxProcent(Discount[] discounts)
- {
- string maxProcent = discounts[0].Code.Substring(2, 2);
- for (int i = 0; i < discounts.Length; i++)
- {
- for (int j = i + 1; j < discounts.Length; j++)
- {
- if (String.Compare(discounts[i].Name, discounts[j].Name) > 0)
- {
- maxProcent = discounts[i].Code.Substring(2, 2);
- }
- }
- }
- return maxProcent;
- }
- }
- namespace _5._06._2018_предварителен_КСИ
- {
- //1. Input
- //2. Sort, Filter, Min.Max element
- //3. Output
- using System;
- class SoftwareSystem
- {
- public string Name { get; set; }
- public DateTime DateandTimeofTheOperation { get; set; }
- public int TypeoftheOperation { get; set; }
- public string Comment { get; set; }
- }
- class Program
- {
- static void Main()
- {
- // TOC
- // 1. input
- //Entering N;
- uint N = EnterNumberN();
- SoftwareSystem[] data = new SoftwareSystem[N];
- EnterData(data);
- OutputElements(data);
- //Sort
- SortByNameAlphabeticaly(data);
- // Output
- OutputElements(data);
- // 4. Въвежда код на суровина. Извежда списък с всички налични суровини в склада
- // с този код.
- string name = Console.ReadLine();
- SoftwareSystem[] dataByName = ReturnMaxOperator( data, name);
- OutputElements(dataByName);
- Console.WriteLine("Max Operator = {0}", ReturnMaxOperator(dataByName));
- //// input
- }
- static uint EnterNumberN()
- {
- Console.Write("Please enter a positive number of the personal data operators: ");
- uint N = uint.Parse(Console.ReadLine());
- return N;
- }
- static void EnterData(SoftwareSystem[] data)
- {
- for (int i = 0; i < data.Length; i++)
- {
- SoftwareSystem datas = new SoftwareSystem();
- Console.WriteLine("------------ Opeartor number {0} -------", i);
- Console.Write("Please, enter a Name of the operator of personal data up to 100 characters: ");
- datas.Name = Console.ReadLine();
- Console.Write("Please, enter a Date and Time of the operation (MM.dd.yyyy HH:mm ): ");
- datas.DateandTimeofTheOperation = DateTime.Parse(Console.ReadLine());
- Console.Write("Please enter a number for the Type of the operation: 1-new data or 2-change of data or 3-delete the data or 4-inquiry with personal data");
- datas.TypeoftheOperation = int.Parse(Console.ReadLine());
- if (datas.TypeoftheOperation == 4)
- {
- Console.Write(" Please enter a name of the enquiry:");
- datas.Comment = Console.ReadLine();
- }
- else
- {
- Console.Write(" Please enter the new, changed or deleted personal datas ");
- datas.Comment = Console.ReadLine();
- }
- data[i] = datas;
- }
- }
- // Метод за сортиране по името на оператора по азбучен ред (сортировка)
- static void SortByNameAlphabeticaly(SoftwareSystem[] data)
- {
- SoftwareSystem swap;
- for (int i = 0; i < data.Length; i++)
- {
- if (data[i] == default(SoftwareSystem)) continue;
- {
- for (int j = i + 1; j < data.Length; j++)
- {
- if (data[j] == default(SoftwareSystem)) continue;
- {
- if (string.Compare(data[i].Name, data[j].Name) > 0)
- {
- swap = data[i];
- data[i] = data[j];
- data[j] = swap;
- }
- if (string.Compare(data[i].Name, data[j].Name) == 0)
- {
- if (string.Compare(data[i].Comment, data[j].Comment) > 0)
- {
- swap = data[i];
- data[i] = data[j];
- data[j] = swap;
- }
- }
- }
- }
- }
- }
- }
- // Метод за намиране на името на оператора с най-много извършени операции?
- //static string MaxOperator(SoftwareSystem[] data)
- //{
- // string name = data[0].Name;
- // SoftwareSystem swap;
- // for (int i = 0; i < data.Length; i++)
- // {
- // if (data[i] == default(SoftwareSystem)) continue;
- // {
- // for (int j = i + 1; j < data.Length; j++)
- // {
- // if (data[j] == default(SoftwareSystem)) continue;
- // {
- // if (string.Compare(data[i].Name, data[j].Name) > 0)
- // {
- // swap = data[i];
- // data[i] = data[j];
- // data[j] = swap;
- // }
- // }
- // }
- // }
- // }
- // return name;
- //}
- static string ReturnMaxOperator(SoftwareSystem[] data)
- {
- string maxName = data[0].Name;// Приема се ,че първия е направил най-много оперцации
- // брояч
- //пази се макс. брой на операциите
- // цикъл , който преброява колко пъти операторатора е направил операцията
- // Взима се първия и се преброява колко пъти се среща и се запазва, взима се втория и се проверя и броя колко пъти операции е направил и го сравнявам с втория
- // Два цикъла- пърия цикъл обхожда целия масив , а втория
- // Първи цикъл - взимам първия и изброявам колко пъти се среща човека и така за другите се изчислява колко пъти се срещат
- // Броячът се увеличава, при всяко завъртане брояча започва от нула от нова за всеки човек
- // В макс се записва настоящ , който има най-много операции
- // Иползва се стринг в началото на метода и се връща името на човека максиме
- // Създава се нови броячи за операция 4 и 1 два цикла проверяващи, ако операторът е максимален и типът на оперцията е равен на 1 и 4 ( в два отделни), увеличавят се броячите , т.е отпечатва всички операции с 1 и 4
- //
- SoftwareSystem swap;
- for (int i = 0; i < data.Length; i++)
- {
- if (data[i] == default(SoftwareSystem)) continue;
- {
- for (int j = i + 1; j < data.Length; j++)
- {
- if (data[j] == default(SoftwareSystem)) continue;
- {
- if (string.Compare(data[i].Name, data[j].Name) > 0)
- {
- swap = data[i];
- data[i] = data[j];
- data[j] = swap;
- }
- }
- }
- }
- }
- return maxName;
- //for (int i = 0; i < data.Length; i++)
- //{
- // if (data[i].Name == name)
- // {
- // filteredByName[i] = data[i];
- // }
- //}
- //return filteredByName;
- }
- // output
- static void OutputElements(SoftwareSystem[] data)
- {
- SoftwareSystem datas = new SoftwareSystem();
- for (int i = 0; i < data.Length; i++)
- {
- string typeOfOperationName = "";
- switch (data[i].TypeoftheOperation)
- {
- case 1:
- typeOfOperationName = "нови данни"; break;
- case 2:
- typeOfOperationName = "промяна на данни"; break;
- case 3:
- typeOfOperationName = "изтриване на данни"; break;
- case 4:
- typeOfOperationName = "справка с лични данни"; break;
- }
- Console.WriteLine("{0:dd.MM.yyyy; HH:mm}; {1}; {2}; {3}; ",
- data[i].DateandTimeofTheOperation,
- data[i].Name,
- typeOfOperationName,
- data[i].Comment
- );
- static string MaxOperations(Operation[]operations)
- } Operation max = operations[0];
- }
- }
- }
- using System;
- namespace _05._06._2019_KSI_full__solution
- {
- // 1.
- using System;
- // 2.
- class Operation
- {
- public string Name { get; set; }
- public DateTime OperationDate { get; set; }
- public int TypeOfOperation { get; set; }
- public string Coment { get; set; }
- }
- // 3.
- class Program
- {
- // 4.
- static void Main()
- {
- Operation[] operations = new Operation[1000];
- // Enter data
- EnterData(operations);
- // Sort by date
- SortByEntryDate(operations);
- OutputData(operations);
- // sort by name
- SortByName(operations);
- OutputDataWithNumbers(operations);
- //
- MaxOperations(operations);
- // Console.WriteLine("{0:dd.MM.yyyy; hh:mm; }", new DateTime(2019, 4, 20, 12, 11, 00));
- }
- // 5. Enter Data
- static void EnterData(Operation[] operations)
- {
- for (int i = 0; i < operations.Length; i++)
- {
- Console.Write("Please enter the name of the operator 100:");
- operations[i].Name = Console.ReadLine();
- Console.Write("Please eneter data: ");
- operations[i].OperationDate = DateTime.Parse(Console.ReadLine());
- Console.Write("Please enter TypeOfOperation (1-4):");
- operations[i].TypeOfOperation = int.Parse(Console.ReadLine());
- if (operations[i].TypeOfOperation == 4)
- {
- Console.Write("Please, eneter the name of the report:");
- operations[i].Coment = Console.ReadLine();
- }
- else
- {
- Console.Write("New, updated or deleted: ");
- operations[i].Coment = Console.ReadLine();
- }
- }
- }
- // 6. Sort
- // 6.1. Sort by date
- static void SortByEntryDate(Operation[] operations)
- {
- Operation temp;
- for (int i = 0; i < operations.Length; i++)
- {
- for (int j = i + 1; j < operations.Length; j++)
- {
- if (DateTime.Compare(operations[i].OperationDate, operations[j].OperationDate) > 0)
- {
- temp = operations[i];
- operations[i] = operations[j];
- operations[j] = temp;
- }
- }
- }
- }
- // 6.2 Sort by name
- static void SortByName(Operation[] operations)
- {
- Operation temp;
- for (int i = 0; i < operations.Length; i++)
- {
- for (int j = i + 1; j < operations.Length; j++)
- {
- if (String.Compare(operations[i].Name, operations[j].Name) > 0)
- {
- temp = operations[i];
- operations[i] = operations[j];
- operations[j] = temp;
- }
- if (String.Compare(operations[i].Name, operations[j].Name) == 0)
- {
- if (String.Compare(operations[i].Coment, operations[j].Coment) > 0)
- {
- temp = operations[i];
- operations[i] = operations[j];
- operations[j] = temp;
- }
- }
- }
- }
- }
- // 7. output
- // 7.1. Without line counter
- static void OutputData(Operation[] operations)
- {
- for (int i = 0; i < operations.Length; i++)
- {
- string typeOfOperation = "";
- switch (operations[i].TypeOfOperation)
- {
- case 1:
- typeOfOperation = "нови данни";
- break;
- case 2:
- typeOfOperation = "промяна на данни";
- break;
- case 3:
- typeOfOperation = "изтриване на данни";
- break;
- case 4:
- typeOfOperation = "справка с лични данни";
- break;
- default:
- break;
- }
- Console.WriteLine("{0:dd.MM.yyyy; hh:mm;} {1}; {2}; {3}", operations[i].OperationDate, operations[i].Name, typeOfOperation, operations[i].Coment);
- }
- }
- // 7.2. With line counter
- static void OutputDataWithNumbers(Operation[] operations)
- {
- for (int i = 0; i < operations.Length; i++)
- {
- string typeOfOperation = "";
- switch (operations[i].TypeOfOperation)
- {
- case 1:
- typeOfOperation = "нови данни";
- break;
- case 2:
- typeOfOperation = "промяна на данни";
- break;
- case 3:
- typeOfOperation = "изтриване на данни";
- break;
- case 4:
- typeOfOperation = "справка с лични данни";
- break;
- default:
- break;
- }
- Console.WriteLine("{0} {1:dd.MM.yyyy; hh:mm;} {2}; {3}; {4}", i, operations[i].OperationDate, operations[i].Name, typeOfOperation, operations[i].Coment);
- }
- }
- // 8. Special function
- static void MaxOperations(Operation[] operations)
- {
- Operation max = operations[0];
- int maxOperations = 0;
- for (int i = 0; i < operations.Length; i++)
- {
- int counter = 0;
- Operation current = operations[i];
- for (int j = 0; j < operations.Length; j++)
- {
- if (current.Name == operations[j].Name)
- {
- counter++;
- }
- }
- if (counter > maxOperations)
- {
- maxOperations = counter;
- max = current;
- }
- }
- Console.WriteLine("The name of the operator with max operations: {0}", max.Name);
- Console.WriteLine("The number of operations {0}", maxOperations);
- int counterOperation4 = 0;
- for (int i = 0; i < operations.Length; i++)
- {
- if (operations[i].Name == max.Name && operations[i].TypeOfOperation == 4)
- {
- counterOperation4++;
- }
- }
- Console.WriteLine("Operations with code 4 {0}", counterOperation4);
- int counterOperation1 = 0;
- for (int i = 0; i < operations.Length; i++)
- {
- if (operations[i].Name == max.Name && operations[i].TypeOfOperation == 1)
- {
- counterOperation1++;
- }
- }
- Console.WriteLine("Operations with code 1 {0}", counterOperation4);
- }
- }
- }
- using System;
- using System.Globalization;
- using System.Threading;
- class Resource
- {
- public string Code { get; set; }
- public string Name { get; set; }
- public double Volume { get; set; }
- public int ExpirationDays { get; set; }
- public char Group { get; set; }
- public DateTime EntryDate { get; set; }
- public string Position { get; set; }
- public int? Humidity { get; set; }
- }
- class Program
- {
- static void Main()
- {
- // 1. Entering N
- uint N = EnterNumberN();
- // 2. Creating the collection of resources
- Resource[] resources = new Resource[N];
- // 3. Entering the resources
- EnterData(resources);
- // 4. Output the elements
- OutputElements(resources);
- }
- static uint EnterNumberN()
- {
- uint N = 0;
- bool isInt = false;
- do
- {
- Console.Write("Please, enter an integer positive number between 0 and 10000 of the resources N = ");
- isInt = uint.TryParse(Console.ReadLine(), out N);
- } while (N < 0 || !isInt || N > 10000);
- return N;
- }
- static void EnterData(Resource[] resources)
- {
- for (int i = 0; i < resources.Length; i++)
- {
- Resource resource = new Resource();
- Console.WriteLine("------------ Resource number {0} -------", i);
- Console.Write("Please, enter the Code up to 4 characters: ");
- resource.Code = Console.ReadLine();
- Console.Write("Please, enter the Name up to 55 characters: ");
- resource.Name = Console.ReadLine();
- Console.Write("Please, enter the Volume real number 2 digits after the decimal point: ");
- resource.Volume = double.Parse(Console.ReadLine());
- Console.Write("Expiration days positive integer number: ");
- resource.ExpirationDays = int.Parse(Console.ReadLine());
- Console.Write("Please enter a group 'E' - special or 'S' - normal: ");
- resource.Group = Console.ReadLine()[0];
- Console.Write("Please, enter the entry date (dd.mm.yyyy): ");
- resource.EntryDate = DateTime.Parse(Console.ReadLine());
- Console.Write("Please, enter the position in the storage (up to 10 characters): ");
- resource.Position = Console.ReadLine();
- if (resource.Group == 'E')
- {
- Console.Write("Please, enter the humidity positive integer number: ");
- resource.Humidity = int.Parse(Console.ReadLine());
- }
- resources[i] = resource;
- }
- }
- static void OutputElements(Resource[] resources)
- {
- Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); //CultureInfo.InvariantCulture;
- for (int i = 0; i < resources.Length; i++)
- {
- if (resources[i].Group == 'E')
- {
- Console.WriteLine("{0}, {1}, {2}, {3:F2}, {4:dd.MM.yyyy}, {5}, В%={6:F2}",
- resources[i].Position,
- resources[i].Code,
- resources[i].Name,
- resources[i].Volume,
- resources[i].EntryDate,
- resources[i].ExpirationDays,
- resources[i].Humidity
- );
- }
- else
- {
- Console.WriteLine("{0}, {1}, {2}, {3:F2}, {4:dd.MM.yyyy}, {5}",
- resources[i].Position,
- resources[i].Code,
- resources[i].Name,
- resources[i].Volume,
- resources[i].EntryDate,
- resources[i].ExpirationDays
- );
- }
- }
- }
- }
- using System;
- namespace ParketFactory
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Hello World!");
- }
- }
- }
- using System;
- namespace KSI
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Hello World!");
- }
- }
- }
- using System;
- namespace Uprajnenie_Recursion
- {
- //class Program
- //{
- // static void Main(string[] args)
- // {
- // Console.Write("Enter n: ");
- // int n = int.Parse(Console.ReadLine());
- // int fibonacci = 0;
- // fibonacci = Fibonacci(n);
- // Console.WriteLine("Fibonacci({0}={1})", n, fibonacci);
- // }
- // static int Fibonacci(int n)
- // {
- // if (n <= 2) return 1;
- // return Fibonacci(n - 1) + Fibonacci(n - 2);
- // }
- // 1,1,2,3,5,8,13,21,34... 0,1,2,3,4
- class StudentsPu
- {
- public string Name { get; set; }
- public int Age { get; set; }
- public DateTime Birthdate { get; set; }
- public string Town { get; set; }
- }
- class Program
- {
- static void Main()
- {
- StudentsPu[] students = new StudentsPu[2];
- InputStudents(students);
- }
- static void InputStudents(StudentsPu[] students)
- {
- for (int i = 0; i < students.Length; i++)
- {
- StudentsPu student = new StudentsPu();
- Console.WriteLine("Please, enter a name for a student {0} : ", i);
- student.Name = Console.ReadLine();
- Console.WriteLine("Please, enter an age for a student {0} : ", i);
- student.Age = int.Parse(Console.ReadLine());
- Console.WriteLine("Please, enter a birth date for a student {0} : ", i);
- student.Birthdate = DateTime.Parse(Console.ReadLine());
- Console.WriteLine("Please, enter a town for a student {0} : ", i);
- student.Town = Console.ReadLine();
- students[i] = student;
- }
- }
- }
- }
- using System;
- //Напишете рекурсивна програма, която генерира и отпечатва всички
- //вариации с повторение на k елемента над n-елементно множество.
- //Примерен вход:
- //n = 3
- //k = 2
- //Примерен изход:
- //Глава 10. Рекурсия 393
- //(1 1), (1 2), (1 3), (2 2), (2 3), (3 3)
- //Измислете и реализирайте итеративен алгоритъм за същата задача.
- //1. Рекурсивното решение е да модифицирате алгоритъма с вложените
- //цикли, че да генерирате k на брой вложени цикъла от 1 до n.
- //Итеративното решение е следното: започнете от първата вариация
- //в лексикографски ред: { 1, …, 1}
- //k пъти.За да намерите следващата
- //вариация, увеличете последното число.Ако стане по-голямо от n,
- //променете го на 1 и увеличете числото вляво от него. Повтаряйте това
- //действие, докато първото число не стане по-голямо от n.
- class RecursiveNestedLoops
- {
- static int numberOfLoops;
- static int numberOfIterations;
- static int[] loops;
- static void Main()
- {
- Console.Write("N = ");
- numberOfLoops = int.Parse(Console.ReadLine());
- Console.Write("K = ");
- numberOfIterations = int.Parse(Console.ReadLine());
- loops = new int[numberOfLoops];
- NestedLoops(0);
- }
- static void NestedLoops(int currentLoop)
- {
- if (currentLoop == numberOfLoops)
- {
- PrintLoops();
- return;
- }
- for (int counter = 1; counter <= numberOfIterations; counter++)
- {
- loops[currentLoop] = counter;
- NestedLoops(currentLoop + 1);
- }
- }
- static void PrintLoops()
- {
- for (int i = 0; i < numberOfLoops; i++)
- {
- Console.Write("{0} ", loops[i]);
- }
- Console.WriteLine();
- }
- }
- using System;
- namespace Recursion
- {
- class Program
- {
- //static void Main()
- //{
- // Console.Write("I will give you the factorial of n. Please, enter n: ");
- // int n = int.Parse(Console.ReadLine());
- // int factorial = Factorial(n);
- // Console.WriteLine("{0}!= {1}", n, factorial);
- //}
- //static int Factorial (int n)
- //{
- // if (n == 0) return 1;
- // return Factorial(n - 1) * n;
- //}
- static void Main()
- {
- Console.Write(" Shte ti kaja cisloto , koeto si wywel ot konzolata na koe syotwetsta ot redicata ot cisla na Fibonacci. Molya, wywedi cislo: ");
- int n = int.Parse(Console.ReadLine());
- int fibonacci = 0;
- fibonacci = Fibonacci(n);
- Console.WriteLine(" Fibonacci ({0})= {1}", n, fibonacci);
- }
- static int Fibonacci (int n)
- {
- if (n <= 0) return 0;
- if (n>0 && n<=2) return 1;
- return Fibonacci(n - 1) + Fibonacci(n - 2);
- }
- }
- }
- using System;
- using System.Globalization;
- using System.Text;
- using System.Threading;
- class Program
- {
- static void Main()
- {
- Console.OutputEncoding = Encoding.UTF8;
- Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US");
- // Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
- Console.WriteLine("Hello World!");
- Console.WriteLine(@"C:\\Windows\\");
- long age = 190005511;
- string name = "Julian";
- Console.WriteLine($"Hi! My name is {name}. I am {age} years old. ");
- Console.WriteLine("Hi! My name is " + name + ". I am " + age + " years old.");
- Console.WriteLine("Hi! My name is {1}. I am {1, 10:#################.0000} years old. ", name, age);
- DateTime d = new DateTime(2019, 10, 23, 15, 30, 22);
- //Console.WriteLine("{0:dd/MM/yyyy HH:mm:ss}",d);
- //Console.WriteLine("{0:d.MM.yy г.}", d);
- Console.WriteLine("{0:D}", d);
- Console.WriteLine("{0:T}", d);
- double myBalance = 213213.12345678;
- Console.WriteLine("My balance is {0:C2}", myBalance);
- Console.Write("Please enter your name: ");
- string myName = Console.ReadLine();
- Console.WriteLine($"Hi,{myName}! I'm glad to meet you!");
- // Console.Write("Please enter a letter: ");
- // int mySymbol = Console.Read();
- // Console.WriteLine(mySymbol);
- Console.Write("Please, enter your age: ");
- int myAge = int.Parse(Console.ReadLine());
- Console.WriteLine("You will be {0} years old after 10 years !", myAge + 10);
- Console.Write("Please enter your balance:");
- double myBalance1;
- bool result= double.TryParse(Console.ReadLine(),out myBalance1);
- Console.WriteLine((result) ? "Thank you!" : "Please enter a correct number!");
- Console.Write("Enter your favourite number:");
- double myNumber = Convert.ToInt32(Console.ReadLine());
- //Console.OutputEncoding=EncodingUTF8;
- Console.WriteLine("Това е кирилица:☺!");
- string number ="100";
- int fromBase = 16;
- int toBase = 10;
- string result1 = Convert.ToString(Convert.ToInt32(number, fromBase), toBase);
- Console.WriteLine(result1);
- }
- }
- using System;
- namespace Chapter2
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine(DateTime.Now);
- string name1 = "Exercise 1";
- Console.WriteLine(name1);
- byte firstNum = 97;
- Console.WriteLine(firstNum);
- sbyte secondNum = 112;
- Console.WriteLine(secondNum);
- byte thirdNum = 224;
- Console.WriteLine(thirdNum);
- ushort forthNum = 1990;
- Console.WriteLine(forthNum);
- ushort fifthNum = 52130;
- Console.WriteLine(fifthNum);
- ushort sixthNum = 20000;
- Console.WriteLine(sixthNum);
- uint seventhNum = 4825932;
- Console.WriteLine(seventhNum);
- uint eigthNum = 970700000;
- Console.WriteLine(eigthNum);
- ulong ninthNum = 123456789123456789;
- Console.WriteLine(ninthNum);
- int tenthNum = -1000000;
- Console.WriteLine(tenthNum);
- short eleventhNum = -10000;
- Console.WriteLine(eleventhNum);
- sbyte twelfthNum = -115;
- Console.WriteLine(twelfthNum);
- sbyte thirtenthNum = -44;
- Console.WriteLine(thirtenthNum);
- string name2 = "Exercise 2";
- Console.WriteLine(name2);
- float floatY = 12.345F;
- Console.WriteLine(floatY);
- double mydoublex = 34.567839023;
- Console.WriteLine(mydoublex);
- double mydoubley = 8923.1234857;
- Console.WriteLine(mydoubley);
- decimal decnum = 3456.0911248759565421512566683467M;
- Console.WriteLine(decnum);
- string name3 = "Exercise 3 ";
- Console.WriteLine(name3);
- decimal number1 = 5.25745243896m;
- decimal number2 = 9.8544531763m;
- number1 += number2;
- Console.WriteLine(number1.ToString("#.######"));
- string name4 = "Exercise 4";
- Console.WriteLine(name4);
- int numberInHex; //declare
- numberInHex = 0x100; // initiliaze
- Console.WriteLine(numberInHex);
- int intValue2 = 0x100;
- Console.WriteLine(intValue2);
- int decn, q, dn = 0, m, l;
- int tmp;
- int s;
- Console.Write("\n\n");
- Console.Write("Convert a number in decimal to hexadecimal:\n");
- Console.Write("---------------------------------------------");
- Console.Write("\n\n");
- Console.Write("Input any Decimal number:");
- decn = Convert.ToInt32(Console.ReadLine());
- q = decn;
- for (l = q; l > 0; l = l / 16)
- {
- tmp = l % 16;
- if (tmp < 10)
- tmp = tmp + 48;
- else
- tmp = tmp + 55;
- dn = dn * 100 + tmp;
- }
- Console.Write("\nThe equivalent Hexadecimal Number : ");
- for (m = dn; m > 0; m = m / 100)
- {
- s = m % 100;
- Console.Write("{0}", (char)s);
- }
- Console.Write("\n\n");
- // Store integer 256
- int intValue = 256;
- // Convert integer 256 as a hex in a string variable
- string hexValue = intValue.ToString("X");
- // Convert the hex string back to the number
- int intAgain = int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber);
- }
- }
- }
- using System;
- namespace Chapter4
- {
- class Program
- {
- static void Main(string[] args)
- {
- // Напишете програма, която чете от конзолата три числа от тип int и
- //отпечатва тяхната сума.
- // Използвайте методите Console.ReadLine() и Int32.Parse().
- string a = Console.ReadLine();
- int number1 = Convert.ToInt32(a);
- string b = Console.ReadLine();
- int number2 = Convert.ToInt32(b);
- string c = Console.ReadLine();
- int number3 = Convert.ToInt32(c);
- Console.WriteLine("You entered : {0},{1},{2}", number1, number2, number3);
- //2.Напишете програма, която чете от конзолата радиуса "r" на кръг и
- //отпечатва неговото лице и обиколка.
- //2.Използвайте константата Math.PI и добре известните формули от
- //планиметрията.
- // Area of Circle
- //Perimeter and Radius of a Circle
- {
- Console.Write("Input the radius of the circle:");
- double rad = double.Parse(Console.ReadLine());
- double area = Math.PI * (Math.Pow(rad, 2));
- double peri = 2 * Math.PI * rad;
- Console.WriteLine($"The area is {area:N} and the perimeter is {peri:N}");
- // 3 .Дадена фирма има име, адрес, телефонен номер, факс номер, уеб сайт
- ////и мениджър. Мениджърът има име, фамилия и телефонен номер.
- //Напишете програма, която чете информацията за фирмата и нейния мениджър и я отпечатва след това на конзолата.
- //3.Форматирайте текста с Write(…) или WriteLine(…) подобно на този от
- //примера с писмото, който разгледахме.
- }
- //Company's task
- //Console.Write("Enter company's name: ");
- //string companyName = Console.ReadLine();
- //Console.Write("Enter company's adress: ");
- //string companyAdress = Console.ReadLine();
- //Console.Write("Enter company's telephone number: ");
- //string cp = Console.ReadLine();
- //int companyPhone = Convert.ToInt32(cp);
- //Console.Write("Enter company's fax number: ");
- //string cf = Console.ReadLine();
- //int companyFax = Convert.ToInt32(cf);
- //Console.Write("Enter company's website: ");
- //string companyWebsite = Console.ReadLine();
- //Console.Write("Enter the manager's first and last name: ");
- //string managerName = Console.ReadLine();
- //Console.Write("Enter the manager's phone number: ");
- //string mp = Console.ReadLine();
- //int managerPhone = Convert.ToInt32(mp);
- //Console.WriteLine(" Your company's name is-{0}, Your company's adress-{1}, Your company's telephone number is-{2}, Your company's fax number is -{3}, Your company's website is -{4}, The manager's first and last names are-{5} and the the manager's phone number-{ 6}", companyName, companyAdress, companyPhone, companyFax, companyWebsite, managerName, managerPhone);
- Console.Write("Enter company name: ");
- string compName = Console.ReadLine();
- Console.Write("Enter company address: ");
- string compAddr = Console.ReadLine();
- Console.Write("Enter company phone number: ");
- string compPhone = Console.ReadLine();
- Console.Write("Enter company fax: ");
- string compFax = Console.ReadLine();
- Console.Write("Enter company website: ");
- string compSite = Console.ReadLine();
- Console.Write("Enter company manager: ");
- string compManager = Console.ReadLine();
- Console.Write("Enter manager first name: ");
- string managerFName = Console.ReadLine();
- Console.Write("Enter manager last name: ");
- string managerLName = Console.ReadLine();
- Console.Write("Enter manager phone: ");
- string managerPhone = Console.ReadLine();
- Console.WriteLine("Firm: Name - {0}, Address - {1}, Number - {2}, Fax - {3}, Website - {4}, Manager - {5}", compName, compAddr, compPhone, compFax, compSite, compManager);
- Console.WriteLine("Manager: Name - {0} {1}, Phone - {2}", managerFName, managerLName, managerPhone);
- }
- }
- }
- using System;
- namespace Chapter1
- {
- class Program
- {
- static void Main(string[] args)
- {
- // Ex.4
- Console.WriteLine("Hello C#!");
- // Ex.5
- System.Console.WriteLine("Добър ден!");
- // Ex.6
- System.Console.WriteLine("Julain Zhelezchev");
- // Ex.7
- System.Console.WriteLine("1");
- System.Console.WriteLine("101");
- System.Console.WriteLine("1001");
- // Ex.8
- System.Console.WriteLine(System.DateTime.Now);
- }
- }
- }
- using System;
- namespace Problem1
- {
- class Program
- {
- static void Main()
- {
- // Напишете програма, която отпечатва на конзолата числата от 1 до N.
- //Числото N трябва да се чете от стандартния вход.
- // 1.Използвайте for цикъл.
- Console.Write("Enter n = ");
- int n = int.Parse(Console.ReadLine());
- for (int i = 1; i < n; i++)
- {
- Console.WriteLine(i);
- }
- }
- }
- }
- using System;
- namespace Problem2
- {
- class Program
- {
- static void Main()
- {
- // Напишете програма, която отпечатва на конзолата числата от 1 до N, които не се делят едновременно на 3 и 7.
- //Числото N да се чете от стандартния вход.
- // Използвайте for цикъл и оператора % за намиране на остатък при целочислено деление.
- //Едно число num не се дели на 3 и на 7 едновременно, ако(num % (3 * 7) == 0).
- Console.WriteLine("Please enter your number: ");
- int n = int.Parse(Console.ReadLine());
- for (int i = 1; i <= n; i++)
- {
- if (i % 3 == 0)
- {
- continue;
- }
- else if (i % 7 == 0)
- {
- continue;
- }
- Console.WriteLine("{0} ", i);
- }
- }
- }
- }
- using System;
- namespace Problem1_
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.Write("Enter first number: ");
- int a = Int32.Parse(Console.ReadLine());
- Console.Write("Enter second number: ");
- int b = Int32.Parse(Console.ReadLine());
- if (a > b)
- {
- a = a + b;
- b = a - b;
- a = a - b;
- }
- Console.WriteLine("First number - {0}, Second number - {1}.", a, b);
- }
- }
- }
- using System;
- namespace Problem2
- {
- class Program
- {
- static void Main()
- {
- Console.WriteLine("You can enter 0 or any positive or any negative number and I will tell you whether the result of their multiplication will be a positive or a negative number or zero.");
- Console.Write(" Please,enter the first number: ");
- int a = Int32.Parse(Console.ReadLine());
- Console.Write(" Please, enter the second number: ");
- int b = Int32.Parse(Console.ReadLine());
- Console.Write(" Please, enter the third number: ");
- int c = Int32.Parse(Console.ReadLine());
- if (a < 0 & b < 0 & c < 0)
- {
- Console.WriteLine("The sign is -");
- }
- else if (a < 0 & b > 0 & c > 0)
- {
- Console.WriteLine("The sign is - ");
- }
- else if (c < 0 & a > 0 & b > 0)
- {
- Console.WriteLine("The sign is -");
- }
- else if (b < 0& c > 0 & a > 0)
- {
- Console.WriteLine("The sign is - ");
- }
- else if (a > 0 & b > 0 & c > 0)
- {
- Console.WriteLine("The sign is + ");
- }
- else if (a <0 & b <0 & c>0)
- {
- Console.WriteLine("The sign is + ");
- }
- else if (b <0 & c<0 & a>0)
- {
- Console.WriteLine("The sign is + ");
- }
- else if (c<0 & a<0 & b>0)
- {
- Console.WriteLine("The sign is + ");
- }
- else if (a>=0 & b>=0 & c>=0)
- Console.WriteLine("The result is zero");
- }
- }
- }
- using System;
- namespace Problem3
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.Write("Enter first number: ");
- int a = Int32.Parse(Console.ReadLine());
- Console.Write("Enter second number: ");
- int b = Int32.Parse(Console.ReadLine());
- Console.Write("Enter third number: ");
- int c = Int32.Parse(Console.ReadLine());
- if (a > b)
- if (a > c) Console.WriteLine("A is the biggest");
- else if (a < c) Console.WriteLine("C is the biggest");
- else Console.WriteLine("A and C are the biggest");
- else if (a < b)
- if (b > c) Console.WriteLine("B is the biggest");
- else if (b < c) Console.WriteLine("C is the biggest");
- else Console.WriteLine("B and C are the biggest");
- else if (a == b)
- if (a == c) Console.WriteLine("All are equal");
- else if (a < c) Console.WriteLine("C is the biggest");
- else Console.WriteLine("A and B are the biggest");
- }
- }
- }
- using System;
- namespace Problem3
- {
- class Program
- {
- static void Main()
- {
- //Напишете израз, който да проверява дали третата цифра(отдясно на ляво) на дадено цяло число е 7.
- // Разделете числото на 100 и го запишете в нова променлива. Нея разделете на 10 и вземете остатъкът.Остатъкът от делението на 10 е третата цифра от първоначалното число. Проверете равна ли е на 7.
- int number = 45764;
- bool isSeven = (number / 100) % 10 == 7 ? true : false;
- Console.WriteLine("Third digit of {0} is 7", number, isSeven);
- }
- }
- }
- using System;
- namespace Problem1
- {
- class Program
- {
- static void Main()
- {
- // 1.Напишете израз, който да проверява дали дадено цяло число е четно или нечетно.
- // Вземете остатъкът от деленето на числото на 2 и проверете дали е 0 или 1(съответно числото е четно или нечетно).Използвайте оператора % за пресмятане на остатък от целочислено деление.
- int number = 23;
- bool even = number % 2 == 0 ? true : false;
- Console.WriteLine("{0} is even? {1}", number, even);
- }
- }
- }
- using System;
- namespace Problem2
- {
- class Program
- {
- static void Main()
- {
- // 2.Напишете булев израз, който да проверява дали дадено цяло число се дели на 5 и на 7 без остатък.
- // Ползвайте логическо "И"(оператора &&) и операцията % за остатък при деление.Можете да решите задачата и чрез само една проверка – за деление на 35(помислете защо).
- int number = 36;
- bool divisible = number % 35 == 0 ? true : false;
- Console.WriteLine("{0} is divisible by both 5 and 7? {1}", number, divisible);
- }
- }
- }
- using System;
- namespace Problem3
- {
- class Program
- {
- static void Main()
- {
- //Напишете израз, който да проверява дали третата цифра(отдясно на ляво) на дадено цяло число е 7.
- // Разделете числото на 100 и го запишете в нова променлива. Нея разделете на 10 и вземете остатъкът.Остатъкът от делението на 10 е третата цифра от първоначалното число. Проверете равна ли е на 7.
- int number = 45764;
- bool isSeven = (number / 100) % 10 == 7 ? true : false;
- Console.WriteLine("Third digit of {0} is 7", number, isSeven);
- }
- }
- }
- using System;
- namespace Problem4
- {
- class Program
- {
- static void Main()
- {
- // Да се напише програма, която преобразува десетично число в двоично.
- // Правилото е "делим на 2 и долепяме остатъците в обратен ред".
- //За делене с остатък използваме оператора %.Можете да се изхитрите,
- //като използвате Convert.ToString(numDecimal, 2).
- String number = "100";
- int fromBase = 10;
- int toBase = 2;
- String result = Convert.ToString(Convert.ToInt32(number, fromBase), toBase);
- Console.WriteLine(result); // result 1100100
- / Convert to binary system
- Console.Write("Please, enter a number to convert to binary: ");
- // with 340282366920938000000000000000000000000
- // System.OverflowException: Value was either too large or too small for an Int32.
- int number2Convert = int.Parse(Console.ReadLine());
- int[] binaryNumber = new int[128]; // the default value is 0
- int digitCounter = 127;
- while (number2Convert > 0 && digitCounter > 0)
- {
- binaryNumber[digitCounter] = number2Convert % 2;
- digitCounter--;
- number2Convert /= 2;
- Console.WriteLine(number2Convert);
- }
- foreach (var digit in binaryNumber)
- {
- Console.Write(digit);
- }
- Console.WriteLine();
- Console.WriteLine(Math.Pow(2, 128)); // 3.40282366920938E+38
- // Console.WriteLine("{0,10:N}", Math.Pow(2, 128)); // 340,282,366,920,938,000,000,000,000,000,000,000,000.00
- // Console.WriteLine("{0,10:D}", Math.Pow(2, 128)); // Exception
- Console.WriteLine("{0,10:F0}", Math.Pow(2, 128)); // 340282366920938000000000000000000000000
- }
- }
- }
- using System;
- namespace Problem1
- {
- class Program
- {
- static void Main()
- {
- // 1.Превърнете числата 151, 35, 43, 251, 1023 и 1024 в двоична
- // бройна система.
- // Използвайте методите за превръщане от една бройна система в
- //друга.Можете да сверите резултатите си с калкулатора на Windows,
- //който поддържа работа с бройни системи след превключване в режим
- //"Programmer".Резултатите са 10010111, 100011, 11111011, 1111111111 и
- //10000000000.
- // 151:2 = 75 остатък 1;
- // 75:2 = 37 остатък 1;
- // 37:2= 18 остатък 1;
- // 18:2= 9 остатък 0;
- // 9:2= 4 остатък 1;
- // 4:2=2 остатък 0;
- // 2:2=1 остатък 0;
- // 1:2=0 остатък 1;
- //151(10)=10010111(2)
- // 35:2=17 остатък 1;
- // 17:2= 8 остатък 1;
- // 8:2= 4 остатък 0;
- // 4:2= 2 остатък 0;
- // 2:2= 1 остатък 0;
- // 1:2=0 остатък 1;
- // 32(10)= 100011(2)
- //43:2= 21 остатък 1;
- //21:2=10 остатък 1;
- //10:2=5 остатък 0;
- //5:2=2 остатък 1;
- //2:2=1 остатък 0;
- //1:2=0 остатък 1;
- // 43(10)=101011(2)
- //251:2= 125 остатък 1;
- //125:2= 62 остатък 1;
- //62:2= 31 остатък 0;
- //31:2= 15 остатък 1;
- //15:2= 7 остатък 1;
- //7:2 = 3 остатък 1;
- //3:2= 1 остатък 1;
- //1:2=0 остатък 1;
- //251(10)= 11111011(2)
- //1023:2= 511 остатък 1;
- //511:2= 255 остатък 1;
- //255:2= 127 остатък 1;
- //127:2= 63 остатък 1;
- //63:2= 31 остатък 1;
- //31:2= 15 остатък 1;
- //15:2 = 7 остатък 1;
- //7:2= 3 остатък 1;
- //3:2=1 остатък 1;
- //1:2=0 остатък 1;
- //1023(10)= 1111111111(2)
- //1024:2= 512 остатък 0;
- //512:2= 256 остатък 0;
- //256:2= 128 остатък 0;
- //128:2= 64 остатък 0;
- //64:2= 32 остатък 0;
- //32:2= 16 остатък 0;
- //16:2= 8 остатък 0;
- //8:2= 4 остатък 0;
- //4:2=2 остатък 0;
- //2:2=1 остатък 0;
- //1:2= 0 остатък 1;
- //1024(10)= 10000000000(2)
- }
- }
- }
- using System;
- namespace Problem2
- {
- class Program
- {
- static void Main()
- {
- // Превърнете числото 1111010110011110(2) в шестнадесетична и в десетична бройна система.
- //Погледнете упътването за предходната задача.Резултат: F59E(16) и
- //62878(10).
- // 1111 0101 1001 1110
- // 15 = F; 5 9 14=E
- // 1111010110011110(2) = F59E(16);
- // 1111010110011110
- //(1*2^15)+(1 * 2 ^14)+(1 * 2 ^13)+(1 * 2 ^12)+ 0 +(1 * 2 ^10)+ 0 +(1 * 2 ^8)+(1 * 2 ^7)+ 0 + 0+(1 * 2 ^4)+(1 * 2 ^3)+(1 * 2 ^2)+(1 * 2 ^1)+ 0=
- // = 32,768+ 16,384 + 8,192 + 4,096 + 1,024 + 256 + 128 + 16 + 8 + 4 + 2 = 62878(10);
- }
- }
- }
- using System;
- namespace Problem3
- {
- class Program
- {
- static void Main()
- {
- //Превърнете шестнайсетичните числа 2A3E, FA, FFFF, 5A0E9 в
- //двоична и десетична бройна система.
- // Погледнете упътването за предходната задача.Резултати:
- //FA(16) = 250(10) = 11111010(2), 2A3E(16) = 10814(10) =
- //10101000111110(2), FFFF(16) = 65535(10) = 1111111111111111(2), 5A0E9(16) =
- //368873(10) = 1011010000011101001(2).
- 2A3E(16) 16→2;
- 2 A=10 3 E=14
- 0010 1010 0011 1110 = 0010101000111110(2);
- 2A3E(16) 16→10;
- Е*16^0+ 3*16^1 + A*16^2 + 2*16^3= 14* 16 ^ 0+ 3 * 16 ^ 1+ 10* 16 ^ 2+ 2 * 16 ^ 3= 14 + 48 + 2560+ 8192= 10814(10)
- FA(16) 16→2;
- F=15 A=10
- 1111 1010 = 11111010(2);
- FA(16) 16→10;
- 15*16^1+ 10*16^0= 240+ 10 =250(10)
- FFFF(16) 16→2;
- F = 15
- 1111 1111 1111 1111 = 1111111111111111(2);
- FFFF(16) 16→10
- 15 * 16 ^ 0 + 15 * 16 ^ 1 + 15 * 16 ^ 2 + 15 * 16 ^ 3 = 15 + 240 + 3840 + 61440 = 65535(10);
- 5A0E9(16) 16→2;
- 5 A=10 0 E=14 9
- 0101 1010 0000 1110 1001 = 01011010000011101001(2);
- 5A0E9(16) 16→10;
- 9 * 16 ^ 0 + 14 * 16 ^ 1 + 0 * 16 ^ 2 + 10 * 16 ^ 3 + 5 * 16 ^ 4 = 9 + 224 + 0 + 40960 + 327680 = 368873(10);
- }
- }
- }
- using System;
- namespace Problem4
- {
- class Program
- {
- static void Main()
- {
- // Да се напише програма, която преобразува десетично число в двоично.
- // Правилото е "делим на 2 и долепяме остатъците в обратен ред".
- //За делене с остатък използваме оператора %.Можете да се изхитрите,
- //като използвате Convert.ToString(numDecimal, 2).
- String number = "100";
- int fromBase = 10;
- int toBase = 2;
- String result = Convert.ToString(Convert.ToInt32(number, fromBase), toBase);
- Console.WriteLine(result); // result 1100100
- / Convert to binary system
- Console.Write("Please, enter a number to convert to binary: ");
- // with 340282366920938000000000000000000000000
- // System.OverflowException: Value was either too large or too small for an Int32.
- int number2Convert = int.Parse(Console.ReadLine());
- int[] binaryNumber = new int[128]; // the default value is 0
- int digitCounter = 127;
- while (number2Convert > 0 && digitCounter > 0)
- {
- binaryNumber[digitCounter] = number2Convert % 2;
- digitCounter--;
- number2Convert /= 2;
- Console.WriteLine(number2Convert);
- }
- foreach (var digit in binaryNumber)
- {
- Console.Write(digit);
- }
- Console.WriteLine();
- Console.WriteLine(Math.Pow(2, 128)); // 3.40282366920938E+38
- // Console.WriteLine("{0,10:N}", Math.Pow(2, 128)); // 340,282,366,920,938,000,000,000,000,000,000,000,000.00
- // Console.WriteLine("{0,10:D}", Math.Pow(2, 128)); // Exception
- Console.WriteLine("{0,10:F0}", Math.Pow(2, 128)); // 340282366920938000000000000000000000000
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement