Advertisement
SUni2020

Предварителни изпити

Jul 18th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 84.16 KB | None | 0 0
  1.  
  2.  
  3. namespace _2._7._2018_KSI
  4. {
  5. using System;
  6.  
  7. using System.Globalization;
  8.  
  9. using System.Threading;
  10.  
  11.  
  12.  
  13. class Resource
  14.  
  15. {
  16.  
  17. public string Code { get; set; }
  18.  
  19. public string Name { get; set; }
  20.  
  21. public double Volume { get; set; }
  22.  
  23. public int ExpirationDays { get; set; }
  24.  
  25. public char Group { get; set; }
  26.  
  27. public DateTime EntryDate { get; set; }
  28.  
  29. public string Position { get; set; }
  30.  
  31. public int? Humidity { get; set; }
  32.  
  33. }
  34.  
  35.  
  36.  
  37.  
  38.  
  39. class Program
  40.  
  41. {
  42.  
  43. static void Main()
  44.  
  45. {
  46.  
  47.  
  48.  
  49. // 1. Entering N
  50.  
  51. uint N = EnterNumberN();
  52.  
  53.  
  54.  
  55. // 2. Creating the collection of resources
  56.  
  57. Resource[] resources = new Resource[N];
  58.  
  59.  
  60.  
  61. // 3. Entering the resources
  62.  
  63. EnterData(resources);
  64.  
  65.  
  66.  
  67. // 4. Output the elements
  68.  
  69. OutputElements(resources);
  70.  
  71. }
  72.  
  73.  
  74.  
  75. static uint EnterNumberN()
  76.  
  77. {
  78.  
  79. uint N = 0;
  80.  
  81. bool isInt = false;
  82.  
  83. do
  84.  
  85. {
  86.  
  87. Console.Write("Please, enter an integer positive number between 0 and 10000 of the resources N = ");
  88.  
  89. isInt = uint.TryParse(Console.ReadLine(), out N);
  90.  
  91. } while (N < 0 || !isInt || N > 10000);
  92.  
  93.  
  94.  
  95. return N;
  96.  
  97. }
  98.  
  99.  
  100.  
  101. static void EnterData(Resource[] resources)
  102.  
  103. {
  104.  
  105. for (int i = 0; i < resources.Length; i++)
  106.  
  107. {
  108.  
  109. Resource resource = new Resource();
  110.  
  111.  
  112.  
  113. Console.WriteLine("------------ Resource number {0} -------", i);
  114.  
  115.  
  116.  
  117. Console.Write("Please, enter the Code up to 4 characters: ");
  118.  
  119. resource.Code = Console.ReadLine();
  120.  
  121.  
  122.  
  123. Console.Write("Please, enter the Name up to 55 characters: ");
  124.  
  125. resource.Name = Console.ReadLine();
  126.  
  127.  
  128.  
  129. Console.Write("Please, enter the Volume real number 2 digits after the decimal point: ");
  130.  
  131. resource.Volume = double.Parse(Console.ReadLine());
  132.  
  133.  
  134.  
  135. Console.Write("Expiration days positive integer number: ");
  136.  
  137. resource.ExpirationDays = int.Parse(Console.ReadLine());
  138.  
  139.  
  140.  
  141. Console.Write("Please enter a group 'E' - special or 'S' - normal: ");
  142.  
  143. resource.Group = Console.ReadLine()[0];
  144.  
  145.  
  146.  
  147. Console.Write("Please, enter the entry date (dd.mm.yyyy): ");
  148.  
  149. resource.EntryDate = DateTime.Parse(Console.ReadLine());
  150.  
  151.  
  152.  
  153. Console.Write("Please, enter the position in the storage (up to 10 characters): ");
  154.  
  155. resource.Position = Console.ReadLine();
  156.  
  157.  
  158.  
  159. if (resource.Group == 'E')
  160.  
  161. {
  162.  
  163. Console.Write("Please, enter the humidity positive integer number: ");
  164.  
  165. resource.Humidity = int.Parse(Console.ReadLine());
  166.  
  167. }
  168.  
  169.  
  170.  
  171. resources[i] = resource;
  172.  
  173.  
  174.  
  175. }
  176.  
  177. }
  178.  
  179.  
  180.  
  181. static void OutputElements(Resource[] resources)
  182.  
  183. {
  184.  
  185. Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); //CultureInfo.InvariantCulture;
  186.  
  187.  
  188.  
  189. for (int i = 0; i < resources.Length; i++)
  190.  
  191. {
  192.  
  193. if (resources[i].Group == 'E')
  194.  
  195. {
  196.  
  197. Console.WriteLine("{0}, {1}, {2}, {3:F2}, {4:dd.MM.yyyy}, {5}, В%={6:F2}",
  198.  
  199. resources[i].Position,
  200.  
  201. resources[i].Code,
  202.  
  203. resources[i].Name,
  204.  
  205. resources[i].Volume,
  206.  
  207. resources[i].EntryDate,
  208.  
  209. resources[i].ExpirationDays,
  210.  
  211. resources[i].Humidity
  212.  
  213. );
  214.  
  215. }
  216.  
  217. else
  218.  
  219. {
  220.  
  221. Console.WriteLine("{0}, {1}, {2}, {3:F2}, {4:dd.MM.yyyy}, {5}",
  222.  
  223. resources[i].Position,
  224.  
  225. resources[i].Code,
  226.  
  227. resources[i].Name,
  228.  
  229. resources[i].Volume,
  230.  
  231. resources[i].EntryDate,
  232.  
  233. resources[i].ExpirationDays
  234.  
  235. );
  236.  
  237. }
  238.  
  239.  
  240.  
  241. }
  242.  
  243. }
  244.  
  245.  
  246.  
  247. }
  248.  
  249.  
  250. }
  251.  
  252.  
  253. // Включваме простраството от имена System
  254. using System;
  255. // Клас за дефиниране на обeкти
  256. class Employeesregister
  257. {
  258. public string Name { get; set; }
  259. public string EGN { get; set; }
  260. public string NamewithLatinletters { get; set; }
  261. public string Domicile { get; set; }
  262. public string CyrrilycName { get; set; } //?
  263. public string FirstName { get; set; } //?
  264. public string SurName { get; set; } //?
  265. public string FamilyName { get; set; } //?
  266. }
  267. // Kлас с програмата
  268. class Program
  269. {
  270. // Основен метод на програмата. Входна точка.
  271. static void Main()
  272. { // 1. Въвеждаме броя на служителите
  273. uint N = EnterNumberN();
  274. Employeesregister[] datas = new Employeesregister[N];
  275.  
  276. // 2. Извикване на метод за въвеждане на данните на служителите
  277. InputData(datas);
  278.  
  279. // 3. Извикваме метода за сортировка на служителите по държава, а тези които са от една и съща държава-сортирани по азбучен ред на името
  280. SortByCountryAndName(datas);
  281. // Извикваме метода за извеждане нa служителите
  282. OutputData(datas);
  283.  
  284. // Да се изведе списък със служителите, за които не са въведени задължителните полета.Списъкът да е
  285. //сортиран по ЕГН
  286. // 4. Извикваме метода за филтриране на служителите, които не са въвели задължителните полета
  287. Employeesregister[] filteredByunfilledBoxes = FilterByUnfilledBoxes(datas);
  288.  
  289. // 5. Извикваме метода за сортировка на служителите по ЕГН , които не са въвели задължителните полета
  290. SortByEGN(filteredByunfilledBoxes);
  291.  
  292. // 6. Извикваме метода за извеждане на служителите
  293. OutputData(filteredByunfilledBoxes);
  294.  
  295. // За всеки един от служителите трябва да се генерира име на служебна поща по
  296. // следния начин(данните извличаме от името с латински букви, ако не е празно):
  297. // ‹Фамилия›_‹Име›_‹Първата буква от бащиното име›@nncomputers.com.
  298. //Ако в името на английски липсват бащино, или първо и бащино име, те се пропускат
  299. //при генерирането на пощата.Да се изведе списък с имената на новите служители и
  300. //пощата, за които името на пощата е генерирано успешно. За примера в точка две
  301. //резултатът ще бъде:
  302. //Иван Петров Иванов, email: Ivanov_Ivan @nncomputers.com
  303. // 7. Извикваме метода за филтриране на служителите, които са въвели име с латински букви
  304. Employeesregister[] filteredByEmail = FilterByEmail(datas);
  305. // Извикваме метода за извеждане на служителите
  306. OutputPost(filteredByEmail);
  307. // 8. Извикваме метода за извеждане на служебна поща на служителите
  308. OutputPost(datas);
  309. }
  310.  
  311. //1. Въвеждаме броя на служителите
  312. static uint EnterNumberN()
  313. {
  314. Console.Write("Please enter the number of employees: ");
  315. uint N = uint.Parse(Console.ReadLine());
  316. return N;
  317. }
  318. //2. Дeфиниране на метода за въвеждане на данните на служителите
  319. static void InputData(Employeesregister[] datas)
  320. {
  321. for (int i = 0; i < datas.Length; i++)
  322. {
  323. Employeesregister data = new Employeesregister();
  324.  
  325. Console.WriteLine("------------ Employee number {0} -------", i);
  326. Console.Write("Please enter the name of the operator up to 50 characters :");
  327. data.Name = Console.ReadLine();
  328. Console.Write("Please enter EGN up to 15 characters: ");
  329. data.EGN = Console.ReadLine();
  330. Console.Write("Please enter a name with Latin letters up to 50 characters :");
  331. data.NamewithLatinletters = Console.ReadLine();
  332. Console.Write("Please enter a domicile ( a country, a postal code, a city-strings up to 30 characters) :");
  333. data.Domicile = Console.ReadLine();
  334.  
  335. // добавяме служителя в масива
  336. datas[i] = data;
  337. }
  338.  
  339. }
  340. //3. Дефинираме метод за сортиране на служителите (по метода на мехурчето) по държава, а тези които са от една и съща държава-сортирани по азбучен ред на името
  341. static void SortByCountryAndName(Employeesregister[] datas)
  342. {
  343. Employeesregister swap;
  344. for (int i = 0; i < datas.Length; i++)
  345. {
  346. if (datas[i] == default(Employeesregister)) continue;
  347. {
  348. for (int j = i + 1; j < datas.Length; j++)
  349. {
  350. if (datas[j] == default(Employeesregister)) continue;
  351. {
  352. if (string.Compare(datas[i].Domicile, datas[j].Domicile) > 0)
  353. {
  354. swap = datas[i];
  355. datas[i] = datas[j];
  356. datas[j] = swap;
  357. }
  358. if (string.Compare(datas[i].Domicile, datas[j].Domicile) == 0)
  359. {
  360. if (string.Compare(datas[i].Name, datas[j].Name) > 0)
  361. {
  362. swap = datas[i];
  363. datas[i] = datas[j];
  364. datas[j] = swap;
  365. }
  366. }
  367. }
  368. }
  369. }
  370. }
  371. }
  372.  
  373. //4. Дефиниране на метод за филтриране на служителите, които не са въвели задължителните полета
  374. static Employeesregister[] FilterByUnfilledBoxes(Employeesregister[] datas)
  375. {
  376. Employeesregister[] filteredByunfilledBoxes = new Employeesregister[datas.Length];
  377. Employeesregister data = new Employeesregister();
  378. for (int i = 0; i < datas.Length; i++)
  379. {
  380. if (data.Name == null)
  381. {
  382. filteredByunfilledBoxes[i] = datas[i];
  383. }
  384. if (data.EGN == null)
  385. {
  386. filteredByunfilledBoxes[i] = datas[i];
  387. }
  388. if (data.NamewithLatinletters == null)
  389. {
  390. filteredByunfilledBoxes[i] = datas[i];
  391. }
  392. if (data.Domicile == null)
  393. {
  394. filteredByunfilledBoxes[i] = datas[i];
  395. }
  396.  
  397. }
  398. return filteredByunfilledBoxes;
  399. }
  400.  
  401. //5. Дефинираме метода за сортировка на служителите по ЕГН , които не са въвели задължителните полета
  402. static void SortByEGN(Employeesregister[] datas)
  403. {
  404. Employeesregister temp;
  405. for (int i = 0; i < datas.Length; i++)
  406. {
  407. for (int j = i + 1; j < datas.Length; j++)
  408. {
  409. if (String.Compare(datas[i].EGN, datas[j].EGN) > 0)
  410. {
  411. temp = datas[i];
  412. datas[i] = datas[j];
  413. datas[j] = temp;
  414. }
  415. }
  416. }
  417. }
  418.  
  419. //6. Дефиниране на метода за извеждане на служителите
  420. static void OutputData(Employeesregister[] data)
  421. {
  422. for (int i = 0; i < data.Length; i++)
  423. {
  424. Console.WriteLine("{0}, {1}, {2}, {3} ",
  425. data[i].Name,
  426. data[i].EGN,
  427. data[i].NamewithLatinletters,
  428. data[i].Domicile
  429. );
  430. }
  431. }
  432.  
  433. // 7. Дефиниране на метода за въвеждане
  434. static void InputPost(Employeesregister[] datas)
  435. {
  436. for (int i = 0; i < datas.Length; i++)
  437. {
  438. Employeesregister data = new Employeesregister();
  439.  
  440. if (datas[i].NamewithLatinletters != null)
  441. {
  442.  
  443. Console.Write("Please enter CyrrilycName :");
  444. data.CyrrilycName = Console.ReadLine();
  445. Console.Write("Please enter first name :");
  446. data.FirstName = Console.ReadLine();
  447. Console.Write("Please enter surname :");
  448. data.SurName = Console.ReadLine();
  449. Console.Write("Please enter family name :");
  450. data.FamilyName = Console.ReadLine();
  451. }
  452. datas[i] = data;
  453. }
  454.  
  455.  
  456.  
  457. //7. Дефинираме метода за филтриране на служителите, които са въвели име с латински букви
  458. static Employeesregister[] FilterByEmail(Employeesregister[] datas)
  459. {
  460. Employeesregister[] filteredByEmail = new Employeesregister[datas.Length];
  461. for (int i = 0; i < datas.Length; i++)
  462. {
  463. if (datas[i].NamewithLatinletters != null)
  464. {
  465. filteredByEmail[i] = datas[i];
  466. }
  467. }
  468. return filteredByEmail;
  469. }
  470.  
  471. //8. Дефиниране на метода за извеждане на служебна поща на служителите
  472. static void OutputPost(Employeesregister[] datas)
  473. {
  474. for (int i = 0; i < datas.Length; i++)
  475. {
  476.  
  477. if (datas[i].SurName != null)
  478. if (datas[i].FirstName !=null)
  479. {
  480. Console.WriteLine("{0}, email: {1}_{2}@nncomputers.com",
  481. datas[i].CyrrilycName,
  482. datas[i].FamilyName,
  483. datas[i].FirstName
  484. );
  485. }
  486. }
  487. }
  488. }
  489.  
  490.  
  491. // Включваме простраството от имена System
  492. using System;
  493.  
  494. // Клас за дефиниране на обeкти
  495. class Discount
  496. {
  497. public string Name { get; set; }
  498. public string City { get; set; }
  499. public string Code { get; set; }
  500. //public int CategoryofGoods { get; set; }
  501. //public int DiscountCode { get; set; }
  502. //public string Percent { get; set; }
  503. //public DateTime Date { get; set; }
  504. }
  505.  
  506. // Kлас с програмата
  507. class Program
  508. {
  509. // Основен метод на програмата. Входна точка.
  510. static void Main()
  511. {
  512.  
  513. // 1. Въвеждаме броя на клиентите
  514. uint N = EnterNumberN();
  515. Discount[] discounts = new Discount[N];
  516.  
  517. //2. Извикване на метод за въвеждане на клиентите
  518. InputData(discounts);
  519.  
  520. //3. Извикваме метода за сортировка на имената на клиентите по азбучен ред
  521. SortByName(discounts);
  522.  
  523. //4. Извикваме метода за извеждане на клиентите
  524. OutputData(discounts);
  525.  
  526. // Да се изведе списък на клиентите от Пловдив с карта за отстъпки на козметика.
  527. // Изведената информация за клиент да бъде във формата от условие 2.Списъкът да се
  528. //подреди в нарастващ ред по процентна отстъпка, а при еднаква стойност клиентите да
  529. //бъдат подредени по име в азбучен ред.
  530.  
  531. //Да се изведе списък на клиентите от Пловдив с карта за отстъпки на козметика.
  532. //5. Филтрираме клиентите от Пловдив с карта за отстъпки на козметика
  533. Discount[] filteredByCityAndCategory = FilterByCityAndCategory(discounts);
  534.  
  535. // Списъкът да се
  536. //подреди в нарастващ ред по процентна отстъпка, а при еднаква стойност клиентите да
  537. //бъдат подредени по име в азбучен ред.
  538.  
  539.  
  540. //6. Извикваме метода за сортировка на списъка в нарастващ ред по процентна отстъпка, а при еднаква стойност клиентите са подредени
  541. // по име в азбучен ред.
  542. SortByPercentDiscoundAndName(filteredByCityAndCategory);
  543. //Изведената информация за клиент да бъде във формата от условие 2.
  544. OutputData(filteredByCityAndCategory);
  545. ////Изведената информация за клиент да бъде във формата от условие 2.
  546. //OutputData(filteredByCityAndCategory);
  547.  
  548. // Да се въведе категория на стока (например 2). Да се намери и изведе
  549. //максималният процент на отстъпка за въведената категория
  550.  
  551. //7. Намира и извежда максимал ният процент на отстъпка за въведената категория
  552. Console.WriteLine("Mаксимален процент на отстъпка за въведената категория= {0}", MaxProcent(discounts));
  553. //FindMaxByCode(Discount[] discounts, code);
  554. }
  555.  
  556.  
  557. //1. Въвеждаме броя на клиентите
  558. static uint EnterNumberN()
  559. {
  560. Console.Write("Please enter a number of employees [1;500] : ");
  561. uint N = uint.Parse(Console.ReadLine());
  562. return N;
  563. }
  564.  
  565. //2. Дeфиниция на метода за въвеждане на клиентите
  566. static void InputData(Discount[] discounts)
  567. {
  568. for (int i = 0; i < discounts.Length; i++)
  569. {
  570. Discount discount = new Discount();
  571.  
  572. Console.Write("Please, enter first and family name: ");
  573. discount.Name = Console.ReadLine();
  574.  
  575. Console.Write("Please, enter a city of residence: ");
  576. discount.City = Console.ReadLine();
  577.  
  578. Console.Write("Please, enter category of goods (1– козметика, 2 – парфюми, 3 – аксесоари, 4 – услуги) :");
  579. discount.Code = Console.ReadLine();
  580.  
  581. Console.Write("Please enter a code for discounts (0 – без натрупване, 1 – с натрупване) :");
  582. discount.Code = Console.ReadLine();
  583.  
  584. Console.Write("Please enter a percent of discount 05, 10, 20 или 30: ");
  585. discount.Code = Console.ReadLine();
  586.  
  587. Console.Write("Please, enter the day of issue of card : ");
  588. discount.Code = Console.ReadLine();
  589.  
  590.  
  591. Console.Write("Please, enter the month of issue of card : ");
  592. discount.Code = Console.ReadLine();
  593.  
  594.  
  595. Console.Write("Please, enter the year of issue of card : ");
  596. discount.Code = Console.ReadLine();
  597.  
  598. //Console.Write("Please, enter a category of goods: 1-козметика, 2 – парфюми, 3 – аксесоари, 4 – услуги");
  599. //resource.TenDigitCode = Console.ReadLine();
  600. //Console.Write("Please, enter a code for discount: 0 – без натрупване, 1 – с натрупване");
  601. //resource.TenDigitCode = Console.ReadLine();
  602. //Console.Write("Please, enter a percent of the discount : 05, 10, 20 или 30");
  603. //resource.TenDigitCode = Console.ReadLine();
  604. //Console.Write("Please, enter two digits for day(..) for month (..) and for year (..) of issue of the card (for example-05/06/17) ");
  605. //resource.TenDigitCode = Console.ReadLine();
  606.  
  607. // добавяме ресурса в масива
  608. discounts[i] = discount;
  609. }
  610. }
  611.  
  612. //3. Дефинираме метода за сортировка на имената на клиентите по азбучен ред
  613. static void SortByName(Discount[] discounts)
  614. {
  615. Discount temp;
  616. for (int i = 0; i < discounts.Length; i++)
  617. {
  618. for (int j = i + 1; j < discounts.Length; j++)
  619. {
  620. if (String.Compare(discounts[i].Name, discounts[j].Name) > 0)
  621. {
  622. temp = discounts[i];
  623. discounts[i] = discounts[j];
  624. discounts[j] = temp;
  625. }
  626.  
  627. }
  628. }
  629. }
  630.  
  631. //4. Дефинираме метода за извеждане на клиентите
  632. static void OutputData(Discount[] discounts)
  633. { //discount.TenDigitCode
  634. //Discount discount = new Discount();
  635. for (int i = 0; i < discounts.Length; i++)
  636. {
  637. string firstDigit = discounts[i].Code.Substring(0,1);
  638. string secondDigit = discounts[i].Code.Substring(1,1);
  639. string thirdDigit = discounts[i].Code.Substring(2,2);
  640. string fourthDigit = discounts[i].Code.Substring(4,2);
  641. string fifthDigit = discounts[i].Code.Substring(6,2);
  642. string sixthDigit = discounts[i].Code.Substring(8,2);
  643.  
  644. string category = "";
  645. //string firstDigit
  646. switch (discounts[i].Code.Substring(0, 1)) // null?
  647. //switch (discounts[i].category)
  648. {
  649. case "1":
  650. category = "козметика";
  651. break;
  652. case "2":
  653. category = "парфюми";
  654. break;
  655. case "3":
  656. category = "аксесоари";
  657. break;
  658. case "4":
  659. category = " услуги";
  660. break;
  661. default:
  662. break;
  663. }
  664.  
  665. string discountCode = "";
  666. switch (discounts[i].Code.Substring(1,1))
  667. {
  668. case "1":
  669. discountCode = " без натрупване";
  670. break;
  671. case "2":
  672. discountCode = "с натрупване";
  673. break;
  674. default:
  675. break;
  676. }
  677. //string percent = discounts[i].TenDigitCode.Substring(2, 2)
  678. //switch (discounts[i].TenDigitCode.Substring(2, 2))
  679. //{
  680. // string Day = "";
  681. //switch (discounts[i].TenDigitCode.Substring(3, 2))
  682. string day = discounts[i].Code.Substring(4, 2);
  683. string month = discounts[i].Code.Substring(6, 2);
  684. string year = discounts[i].Code.Substring(8, 2);
  685.  
  686. Console.WriteLine(" {0}, {1}, {2},{3} {4}.{5}.{6}",
  687. discounts[i].Name,
  688. discounts[i].City,
  689. category, discountCode, day, month, year);
  690. }
  691.  
  692. //Console.WriteLine("{0}, {1}, {2}, {3}, {4}, {5} ",
  693. // discounts[i].Name,
  694. // discounts[i].City,
  695. // categoryofGoods,
  696. // discountCode,
  697. // discounts[i].Percent,
  698. // discounts[i].Date
  699. // );
  700. //}
  701. }
  702. // 5. Дефиниране на метод за филтриране на елементите от Пловдив с карта за отстъпки за козметика(категория стоки-1 козметика)
  703. static Discount[] FilterByCityAndCategory(Discount[] discounts)
  704. {
  705. Discount[] filteredByByCityAndCategory = new Discount[discounts.Length];
  706. for (int i = 0; i < discounts.Length; i++)
  707. {
  708. if (discounts[i].City == "Пловдив")
  709. if (discounts[i].Code.Substring(0, 1) == "1") //"козметика"
  710. {
  711. filteredByByCityAndCategory[i] = discounts[i];
  712. }
  713. }
  714. return filteredByByCityAndCategory;
  715. }
  716.  
  717. //6. Дефиниране на метода за сортировка на списъка в нарастващ ред по процентна отстъпка, а при еднаква стойност клиентите са подредени
  718. // по име в азбучен ред.
  719. static void SortByPercentDiscoundAndName(Discount[] discounts)
  720. {
  721.  
  722. Discount swap;
  723. for (int i = 0; i < discounts.Length; i++)
  724. {
  725. for (int j = i + 1; j < discounts.Length; j++)
  726. {
  727. 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.'
  728.  
  729. //discounts[] was null.
  730. {
  731. swap = discounts[i];
  732. discounts[i] = discounts[j];
  733. discounts[j] = swap;
  734. }
  735.  
  736. if (String.Compare(discounts[i].Code.Substring(2, 2), discounts[j].Code.Substring(2, 2)) == 0)
  737. {
  738. if (String.Compare(discounts[i].Name, discounts[j].Name) > 0)
  739. {
  740. swap = discounts[i];
  741. discounts[i] = discounts[j];
  742. discounts[j] = swap;
  743. }
  744. }
  745. }
  746. }
  747. }
  748.  
  749. // 7. Дефинираме метода за намиране максималният процент на отстъпка за въведената категория
  750. static string MaxProcent(Discount[] discounts)
  751. {
  752. string maxProcent = discounts[0].Code.Substring(2, 2);
  753. for (int i = 0; i < discounts.Length; i++)
  754. {
  755. for (int j = i + 1; j < discounts.Length; j++)
  756. {
  757. if (String.Compare(discounts[i].Name, discounts[j].Name) > 0)
  758. {
  759. maxProcent = discounts[i].Code.Substring(2, 2);
  760. }
  761. }
  762. }
  763. return maxProcent;
  764. }
  765. }
  766.  
  767.  
  768. namespace _5._06._2018_предварителен_КСИ
  769. {
  770. //1. Input
  771. //2. Sort, Filter, Min.Max element
  772. //3. Output
  773. using System;
  774. class SoftwareSystem
  775. {
  776. public string Name { get; set; }
  777. public DateTime DateandTimeofTheOperation { get; set; }
  778. public int TypeoftheOperation { get; set; }
  779. public string Comment { get; set; }
  780. }
  781. class Program
  782. {
  783. static void Main()
  784. {
  785. // TOC
  786. // 1. input
  787. //Entering N;
  788. uint N = EnterNumberN();
  789. SoftwareSystem[] data = new SoftwareSystem[N];
  790. EnterData(data);
  791. OutputElements(data);
  792. //Sort
  793. SortByNameAlphabeticaly(data);
  794. // Output
  795. OutputElements(data);
  796. // 4. Въвежда код на суровина. Извежда списък с всички налични суровини в склада
  797. // с този код.
  798. string name = Console.ReadLine();
  799. SoftwareSystem[] dataByName = ReturnMaxOperator( data, name);
  800. OutputElements(dataByName);
  801. Console.WriteLine("Max Operator = {0}", ReturnMaxOperator(dataByName));
  802. //// input
  803. }
  804.  
  805. static uint EnterNumberN()
  806. {
  807. Console.Write("Please enter a positive number of the personal data operators: ");
  808. uint N = uint.Parse(Console.ReadLine());
  809. return N;
  810. }
  811. static void EnterData(SoftwareSystem[] data)
  812. {
  813. for (int i = 0; i < data.Length; i++)
  814. {
  815. SoftwareSystem datas = new SoftwareSystem();
  816. Console.WriteLine("------------ Opeartor number {0} -------", i);
  817. Console.Write("Please, enter a Name of the operator of personal data up to 100 characters: ");
  818. datas.Name = Console.ReadLine();
  819. Console.Write("Please, enter a Date and Time of the operation (MM.dd.yyyy HH:mm ): ");
  820. datas.DateandTimeofTheOperation = DateTime.Parse(Console.ReadLine());
  821. 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");
  822. datas.TypeoftheOperation = int.Parse(Console.ReadLine());
  823. if (datas.TypeoftheOperation == 4)
  824. {
  825. Console.Write(" Please enter a name of the enquiry:");
  826. datas.Comment = Console.ReadLine();
  827. }
  828. else
  829. {
  830. Console.Write(" Please enter the new, changed or deleted personal datas ");
  831. datas.Comment = Console.ReadLine();
  832. }
  833. data[i] = datas;
  834. }
  835. }
  836. // Метод за сортиране по името на оператора по азбучен ред (сортировка)
  837. static void SortByNameAlphabeticaly(SoftwareSystem[] data)
  838. {
  839. SoftwareSystem swap;
  840. for (int i = 0; i < data.Length; i++)
  841. {
  842. if (data[i] == default(SoftwareSystem)) continue;
  843. {
  844. for (int j = i + 1; j < data.Length; j++)
  845. {
  846. if (data[j] == default(SoftwareSystem)) continue;
  847. {
  848. if (string.Compare(data[i].Name, data[j].Name) > 0)
  849. {
  850. swap = data[i];
  851. data[i] = data[j];
  852. data[j] = swap;
  853. }
  854. if (string.Compare(data[i].Name, data[j].Name) == 0)
  855. {
  856. if (string.Compare(data[i].Comment, data[j].Comment) > 0)
  857. {
  858. swap = data[i];
  859. data[i] = data[j];
  860. data[j] = swap;
  861. }
  862. }
  863. }
  864. }
  865. }
  866. }
  867. }
  868.  
  869. // Метод за намиране на името на оператора с най-много извършени операции?
  870. //static string MaxOperator(SoftwareSystem[] data)
  871. //{
  872. // string name = data[0].Name;
  873. // SoftwareSystem swap;
  874. // for (int i = 0; i < data.Length; i++)
  875. // {
  876. // if (data[i] == default(SoftwareSystem)) continue;
  877. // {
  878. // for (int j = i + 1; j < data.Length; j++)
  879. // {
  880. // if (data[j] == default(SoftwareSystem)) continue;
  881. // {
  882. // if (string.Compare(data[i].Name, data[j].Name) > 0)
  883. // {
  884. // swap = data[i];
  885. // data[i] = data[j];
  886. // data[j] = swap;
  887. // }
  888. // }
  889. // }
  890. // }
  891. // }
  892. // return name;
  893. //}
  894. static string ReturnMaxOperator(SoftwareSystem[] data)
  895. {
  896. string maxName = data[0].Name;// Приема се ,че първия е направил най-много оперцации
  897. // брояч
  898. //пази се макс. брой на операциите
  899. // цикъл , който преброява колко пъти операторатора е направил операцията
  900. // Взима се първия и се преброява колко пъти се среща и се запазва, взима се втория и се проверя и броя колко пъти операции е направил и го сравнявам с втория
  901. // Два цикъла- пърия цикъл обхожда целия масив , а втория
  902. // Първи цикъл - взимам първия и изброявам колко пъти се среща човека и така за другите се изчислява колко пъти се срещат
  903. // Броячът се увеличава, при всяко завъртане брояча започва от нула от нова за всеки човек
  904. // В макс се записва настоящ , който има най-много операции
  905. // Иползва се стринг в началото на метода и се връща името на човека максиме
  906. // Създава се нови броячи за операция 4 и 1 два цикла проверяващи, ако операторът е максимален и типът на оперцията е равен на 1 и 4 ( в два отделни), увеличавят се броячите , т.е отпечатва всички операции с 1 и 4
  907. //
  908. SoftwareSystem swap;
  909. for (int i = 0; i < data.Length; i++)
  910. {
  911. if (data[i] == default(SoftwareSystem)) continue;
  912. {
  913. for (int j = i + 1; j < data.Length; j++)
  914. {
  915. if (data[j] == default(SoftwareSystem)) continue;
  916. {
  917. if (string.Compare(data[i].Name, data[j].Name) > 0)
  918. {
  919. swap = data[i];
  920. data[i] = data[j];
  921. data[j] = swap;
  922. }
  923. }
  924. }
  925. }
  926. }
  927. return maxName;
  928.  
  929. //for (int i = 0; i < data.Length; i++)
  930. //{
  931. // if (data[i].Name == name)
  932. // {
  933. // filteredByName[i] = data[i];
  934. // }
  935. //}
  936. //return filteredByName;
  937.  
  938. }
  939.  
  940. // output
  941. static void OutputElements(SoftwareSystem[] data)
  942. {
  943. SoftwareSystem datas = new SoftwareSystem();
  944. for (int i = 0; i < data.Length; i++)
  945. {
  946. string typeOfOperationName = "";
  947. switch (data[i].TypeoftheOperation)
  948. {
  949. case 1:
  950. typeOfOperationName = "нови данни"; break;
  951. case 2:
  952. typeOfOperationName = "промяна на данни"; break;
  953. case 3:
  954. typeOfOperationName = "изтриване на данни"; break;
  955. case 4:
  956. typeOfOperationName = "справка с лични данни"; break;
  957. }
  958. Console.WriteLine("{0:dd.MM.yyyy; HH:mm}; {1}; {2}; {3}; ",
  959. data[i].DateandTimeofTheOperation,
  960. data[i].Name,
  961. typeOfOperationName,
  962. data[i].Comment
  963. );
  964. static string MaxOperations(Operation[]operations)
  965. } Operation max = operations[0];
  966.  
  967.  
  968. }
  969. }
  970. }
  971.  
  972.  
  973. using System;
  974.  
  975. namespace _05._06._2019_KSI_full__solution
  976. {
  977.  
  978. // 1.
  979. using System;
  980.  
  981. // 2.
  982. class Operation
  983. {
  984. public string Name { get; set; }
  985. public DateTime OperationDate { get; set; }
  986. public int TypeOfOperation { get; set; }
  987. public string Coment { get; set; }
  988. }
  989.  
  990. // 3.
  991. class Program
  992. {
  993. // 4.
  994. static void Main()
  995. {
  996. Operation[] operations = new Operation[1000];
  997.  
  998. // Enter data
  999. EnterData(operations);
  1000.  
  1001. // Sort by date
  1002. SortByEntryDate(operations);
  1003. OutputData(operations);
  1004.  
  1005. // sort by name
  1006. SortByName(operations);
  1007. OutputDataWithNumbers(operations);
  1008.  
  1009. //
  1010. MaxOperations(operations);
  1011. // Console.WriteLine("{0:dd.MM.yyyy; hh:mm; }", new DateTime(2019, 4, 20, 12, 11, 00));
  1012. }
  1013.  
  1014. // 5. Enter Data
  1015. static void EnterData(Operation[] operations)
  1016. {
  1017. for (int i = 0; i < operations.Length; i++)
  1018. {
  1019. Console.Write("Please enter the name of the operator 100:");
  1020. operations[i].Name = Console.ReadLine();
  1021.  
  1022. Console.Write("Please eneter data: ");
  1023. operations[i].OperationDate = DateTime.Parse(Console.ReadLine());
  1024.  
  1025. Console.Write("Please enter TypeOfOperation (1-4):");
  1026. operations[i].TypeOfOperation = int.Parse(Console.ReadLine());
  1027.  
  1028. if (operations[i].TypeOfOperation == 4)
  1029. {
  1030. Console.Write("Please, eneter the name of the report:");
  1031. operations[i].Coment = Console.ReadLine();
  1032. }
  1033. else
  1034. {
  1035. Console.Write("New, updated or deleted: ");
  1036. operations[i].Coment = Console.ReadLine();
  1037. }
  1038. }
  1039. }
  1040.  
  1041. // 6. Sort
  1042. // 6.1. Sort by date
  1043. static void SortByEntryDate(Operation[] operations)
  1044. {
  1045. Operation temp;
  1046. for (int i = 0; i < operations.Length; i++)
  1047. {
  1048. for (int j = i + 1; j < operations.Length; j++)
  1049. {
  1050. if (DateTime.Compare(operations[i].OperationDate, operations[j].OperationDate) > 0)
  1051. {
  1052. temp = operations[i];
  1053. operations[i] = operations[j];
  1054. operations[j] = temp;
  1055. }
  1056. }
  1057. }
  1058. }
  1059.  
  1060. // 6.2 Sort by name
  1061. static void SortByName(Operation[] operations)
  1062. {
  1063. Operation temp;
  1064. for (int i = 0; i < operations.Length; i++)
  1065. {
  1066. for (int j = i + 1; j < operations.Length; j++)
  1067. {
  1068. if (String.Compare(operations[i].Name, operations[j].Name) > 0)
  1069. {
  1070. temp = operations[i];
  1071. operations[i] = operations[j];
  1072. operations[j] = temp;
  1073. }
  1074.  
  1075. if (String.Compare(operations[i].Name, operations[j].Name) == 0)
  1076. {
  1077. if (String.Compare(operations[i].Coment, operations[j].Coment) > 0)
  1078. {
  1079. temp = operations[i];
  1080. operations[i] = operations[j];
  1081. operations[j] = temp;
  1082. }
  1083. }
  1084. }
  1085. }
  1086. }
  1087.  
  1088. // 7. output
  1089. // 7.1. Without line counter
  1090. static void OutputData(Operation[] operations)
  1091. {
  1092. for (int i = 0; i < operations.Length; i++)
  1093. {
  1094. string typeOfOperation = "";
  1095. switch (operations[i].TypeOfOperation)
  1096. {
  1097. case 1:
  1098. typeOfOperation = "нови данни";
  1099. break;
  1100. case 2:
  1101. typeOfOperation = "промяна на данни";
  1102. break;
  1103. case 3:
  1104. typeOfOperation = "изтриване на данни";
  1105. break;
  1106. case 4:
  1107. typeOfOperation = "справка с лични данни";
  1108. break;
  1109. default:
  1110. break;
  1111. }
  1112.  
  1113. Console.WriteLine("{0:dd.MM.yyyy; hh:mm;} {1}; {2}; {3}", operations[i].OperationDate, operations[i].Name, typeOfOperation, operations[i].Coment);
  1114. }
  1115. }
  1116.  
  1117. // 7.2. With line counter
  1118. static void OutputDataWithNumbers(Operation[] operations)
  1119. {
  1120. for (int i = 0; i < operations.Length; i++)
  1121. {
  1122. string typeOfOperation = "";
  1123. switch (operations[i].TypeOfOperation)
  1124. {
  1125. case 1:
  1126. typeOfOperation = "нови данни";
  1127. break;
  1128. case 2:
  1129. typeOfOperation = "промяна на данни";
  1130. break;
  1131. case 3:
  1132. typeOfOperation = "изтриване на данни";
  1133. break;
  1134. case 4:
  1135. typeOfOperation = "справка с лични данни";
  1136. break;
  1137. default:
  1138. break;
  1139. }
  1140.  
  1141. Console.WriteLine("{0} {1:dd.MM.yyyy; hh:mm;} {2}; {3}; {4}", i, operations[i].OperationDate, operations[i].Name, typeOfOperation, operations[i].Coment);
  1142. }
  1143. }
  1144.  
  1145.  
  1146.  
  1147. // 8. Special function
  1148. static void MaxOperations(Operation[] operations)
  1149. {
  1150. Operation max = operations[0];
  1151. int maxOperations = 0;
  1152. for (int i = 0; i < operations.Length; i++)
  1153. {
  1154. int counter = 0;
  1155. Operation current = operations[i];
  1156. for (int j = 0; j < operations.Length; j++)
  1157. {
  1158. if (current.Name == operations[j].Name)
  1159. {
  1160. counter++;
  1161. }
  1162. }
  1163. if (counter > maxOperations)
  1164. {
  1165. maxOperations = counter;
  1166. max = current;
  1167. }
  1168. }
  1169. Console.WriteLine("The name of the operator with max operations: {0}", max.Name);
  1170. Console.WriteLine("The number of operations {0}", maxOperations);
  1171.  
  1172. int counterOperation4 = 0;
  1173. for (int i = 0; i < operations.Length; i++)
  1174. {
  1175. if (operations[i].Name == max.Name && operations[i].TypeOfOperation == 4)
  1176. {
  1177. counterOperation4++;
  1178. }
  1179. }
  1180. Console.WriteLine("Operations with code 4 {0}", counterOperation4);
  1181.  
  1182. int counterOperation1 = 0;
  1183. for (int i = 0; i < operations.Length; i++)
  1184. {
  1185. if (operations[i].Name == max.Name && operations[i].TypeOfOperation == 1)
  1186. {
  1187. counterOperation1++;
  1188. }
  1189. }
  1190. Console.WriteLine("Operations with code 1 {0}", counterOperation4);
  1191. }
  1192. }
  1193. }
  1194. using System;
  1195.  
  1196. using System.Globalization;
  1197.  
  1198. using System.Threading;
  1199.  
  1200.  
  1201.  
  1202. class Resource
  1203.  
  1204. {
  1205.  
  1206. public string Code { get; set; }
  1207.  
  1208. public string Name { get; set; }
  1209.  
  1210. public double Volume { get; set; }
  1211.  
  1212. public int ExpirationDays { get; set; }
  1213.  
  1214. public char Group { get; set; }
  1215.  
  1216. public DateTime EntryDate { get; set; }
  1217.  
  1218. public string Position { get; set; }
  1219.  
  1220. public int? Humidity { get; set; }
  1221.  
  1222. }
  1223.  
  1224.  
  1225.  
  1226.  
  1227.  
  1228. class Program
  1229.  
  1230. {
  1231.  
  1232. static void Main()
  1233.  
  1234. {
  1235.  
  1236.  
  1237.  
  1238. // 1. Entering N
  1239.  
  1240. uint N = EnterNumberN();
  1241.  
  1242.  
  1243.  
  1244. // 2. Creating the collection of resources
  1245.  
  1246. Resource[] resources = new Resource[N];
  1247.  
  1248.  
  1249.  
  1250. // 3. Entering the resources
  1251.  
  1252. EnterData(resources);
  1253.  
  1254.  
  1255.  
  1256. // 4. Output the elements
  1257.  
  1258. OutputElements(resources);
  1259.  
  1260. }
  1261.  
  1262.  
  1263.  
  1264. static uint EnterNumberN()
  1265.  
  1266. {
  1267.  
  1268. uint N = 0;
  1269.  
  1270. bool isInt = false;
  1271.  
  1272. do
  1273.  
  1274. {
  1275.  
  1276. Console.Write("Please, enter an integer positive number between 0 and 10000 of the resources N = ");
  1277.  
  1278. isInt = uint.TryParse(Console.ReadLine(), out N);
  1279.  
  1280. } while (N < 0 || !isInt || N > 10000);
  1281.  
  1282.  
  1283.  
  1284. return N;
  1285.  
  1286. }
  1287.  
  1288.  
  1289.  
  1290. static void EnterData(Resource[] resources)
  1291.  
  1292. {
  1293.  
  1294. for (int i = 0; i < resources.Length; i++)
  1295.  
  1296. {
  1297.  
  1298. Resource resource = new Resource();
  1299.  
  1300.  
  1301.  
  1302. Console.WriteLine("------------ Resource number {0} -------", i);
  1303.  
  1304.  
  1305.  
  1306. Console.Write("Please, enter the Code up to 4 characters: ");
  1307.  
  1308. resource.Code = Console.ReadLine();
  1309.  
  1310.  
  1311.  
  1312. Console.Write("Please, enter the Name up to 55 characters: ");
  1313.  
  1314. resource.Name = Console.ReadLine();
  1315.  
  1316.  
  1317.  
  1318. Console.Write("Please, enter the Volume real number 2 digits after the decimal point: ");
  1319.  
  1320. resource.Volume = double.Parse(Console.ReadLine());
  1321.  
  1322.  
  1323.  
  1324. Console.Write("Expiration days positive integer number: ");
  1325.  
  1326. resource.ExpirationDays = int.Parse(Console.ReadLine());
  1327.  
  1328.  
  1329.  
  1330. Console.Write("Please enter a group 'E' - special or 'S' - normal: ");
  1331.  
  1332. resource.Group = Console.ReadLine()[0];
  1333.  
  1334.  
  1335.  
  1336. Console.Write("Please, enter the entry date (dd.mm.yyyy): ");
  1337.  
  1338. resource.EntryDate = DateTime.Parse(Console.ReadLine());
  1339.  
  1340.  
  1341.  
  1342. Console.Write("Please, enter the position in the storage (up to 10 characters): ");
  1343.  
  1344. resource.Position = Console.ReadLine();
  1345.  
  1346.  
  1347.  
  1348. if (resource.Group == 'E')
  1349.  
  1350. {
  1351.  
  1352. Console.Write("Please, enter the humidity positive integer number: ");
  1353.  
  1354. resource.Humidity = int.Parse(Console.ReadLine());
  1355.  
  1356. }
  1357.  
  1358.  
  1359.  
  1360. resources[i] = resource;
  1361.  
  1362.  
  1363.  
  1364. }
  1365.  
  1366. }
  1367.  
  1368.  
  1369.  
  1370. static void OutputElements(Resource[] resources)
  1371.  
  1372. {
  1373.  
  1374. Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); //CultureInfo.InvariantCulture;
  1375.  
  1376.  
  1377.  
  1378. for (int i = 0; i < resources.Length; i++)
  1379.  
  1380. {
  1381.  
  1382. if (resources[i].Group == 'E')
  1383.  
  1384. {
  1385.  
  1386. Console.WriteLine("{0}, {1}, {2}, {3:F2}, {4:dd.MM.yyyy}, {5}, В%={6:F2}",
  1387.  
  1388. resources[i].Position,
  1389.  
  1390. resources[i].Code,
  1391.  
  1392. resources[i].Name,
  1393.  
  1394. resources[i].Volume,
  1395.  
  1396. resources[i].EntryDate,
  1397.  
  1398. resources[i].ExpirationDays,
  1399.  
  1400. resources[i].Humidity
  1401.  
  1402. );
  1403.  
  1404. }
  1405.  
  1406. else
  1407.  
  1408. {
  1409.  
  1410. Console.WriteLine("{0}, {1}, {2}, {3:F2}, {4:dd.MM.yyyy}, {5}",
  1411.  
  1412. resources[i].Position,
  1413.  
  1414. resources[i].Code,
  1415.  
  1416. resources[i].Name,
  1417.  
  1418. resources[i].Volume,
  1419.  
  1420. resources[i].EntryDate,
  1421.  
  1422. resources[i].ExpirationDays
  1423.  
  1424. );
  1425.  
  1426. }
  1427.  
  1428.  
  1429.  
  1430. }
  1431.  
  1432. }
  1433.  
  1434.  
  1435.  
  1436. }
  1437.  
  1438.  
  1439. using System;
  1440.  
  1441. namespace ParketFactory
  1442. {
  1443. class Program
  1444. {
  1445. static void Main(string[] args)
  1446. {
  1447. Console.WriteLine("Hello World!");
  1448. }
  1449. }
  1450. }
  1451.  
  1452. using System;
  1453.  
  1454. namespace KSI
  1455. {
  1456. class Program
  1457. {
  1458. static void Main(string[] args)
  1459. {
  1460. Console.WriteLine("Hello World!");
  1461. }
  1462. }
  1463. }
  1464.  
  1465. using System;
  1466.  
  1467. namespace Uprajnenie_Recursion
  1468. {
  1469. //class Program
  1470. //{
  1471. // static void Main(string[] args)
  1472. // {
  1473. // Console.Write("Enter n: ");
  1474. // int n = int.Parse(Console.ReadLine());
  1475. // int fibonacci = 0;
  1476. // fibonacci = Fibonacci(n);
  1477. // Console.WriteLine("Fibonacci({0}={1})", n, fibonacci);
  1478. // }
  1479. // static int Fibonacci(int n)
  1480. // {
  1481.  
  1482.  
  1483. // if (n <= 2) return 1;
  1484. // return Fibonacci(n - 1) + Fibonacci(n - 2);
  1485. // }
  1486.  
  1487. // 1,1,2,3,5,8,13,21,34... 0,1,2,3,4
  1488. class StudentsPu
  1489. {
  1490. public string Name { get; set; }
  1491. public int Age { get; set; }
  1492. public DateTime Birthdate { get; set; }
  1493. public string Town { get; set; }
  1494. }
  1495. class Program
  1496. {
  1497. static void Main()
  1498. {
  1499. StudentsPu[] students = new StudentsPu[2];
  1500. InputStudents(students);
  1501. }
  1502.  
  1503. static void InputStudents(StudentsPu[] students)
  1504. {
  1505. for (int i = 0; i < students.Length; i++)
  1506.  
  1507.  
  1508. {
  1509.  
  1510. StudentsPu student = new StudentsPu();
  1511. Console.WriteLine("Please, enter a name for a student {0} : ", i);
  1512. student.Name = Console.ReadLine();
  1513. Console.WriteLine("Please, enter an age for a student {0} : ", i);
  1514. student.Age = int.Parse(Console.ReadLine());
  1515. Console.WriteLine("Please, enter a birth date for a student {0} : ", i);
  1516. student.Birthdate = DateTime.Parse(Console.ReadLine());
  1517. Console.WriteLine("Please, enter a town for a student {0} : ", i);
  1518. student.Town = Console.ReadLine();
  1519.  
  1520. students[i] = student;
  1521.  
  1522.  
  1523. }
  1524.  
  1525.  
  1526.  
  1527. }
  1528.  
  1529.  
  1530.  
  1531. }
  1532.  
  1533. }
  1534.  
  1535.  
  1536.  
  1537.  
  1538.  
  1539. using System;
  1540.  
  1541. //Напишете рекурсивна програма, която генерира и отпечатва всички
  1542. //вариации с повторение на k елемента над n-елементно множество.
  1543. //Примерен вход:
  1544. //n = 3
  1545. //k = 2
  1546. //Примерен изход:
  1547. //Глава 10. Рекурсия 393
  1548. //(1 1), (1 2), (1 3), (2 2), (2 3), (3 3)
  1549. //Измислете и реализирайте итеративен алгоритъм за същата задача.
  1550. //1. Рекурсивното решение е да модифицирате алгоритъма с вложените
  1551. //цикли, че да генерирате k на брой вложени цикъла от 1 до n.
  1552. //Итеративното решение е следното: започнете от първата вариация
  1553. //в лексикографски ред: { 1, …, 1}
  1554. //k пъти.За да намерите следващата
  1555. //вариация, увеличете последното число.Ако стане по-голямо от n,
  1556. //променете го на 1 и увеличете числото вляво от него. Повтаряйте това
  1557. //действие, докато първото число не стане по-голямо от n.
  1558. class RecursiveNestedLoops
  1559. {
  1560. static int numberOfLoops;
  1561. static int numberOfIterations;
  1562. static int[] loops;
  1563. static void Main()
  1564.  
  1565. {
  1566. Console.Write("N = ");
  1567. numberOfLoops = int.Parse(Console.ReadLine());
  1568. Console.Write("K = ");
  1569. numberOfIterations = int.Parse(Console.ReadLine());
  1570. loops = new int[numberOfLoops];
  1571. NestedLoops(0);
  1572. }
  1573. static void NestedLoops(int currentLoop)
  1574. {
  1575. if (currentLoop == numberOfLoops)
  1576. {
  1577. PrintLoops();
  1578. return;
  1579. }
  1580. for (int counter = 1; counter <= numberOfIterations; counter++)
  1581. {
  1582. loops[currentLoop] = counter;
  1583. NestedLoops(currentLoop + 1);
  1584. }
  1585. }
  1586. static void PrintLoops()
  1587. {
  1588. for (int i = 0; i < numberOfLoops; i++)
  1589. {
  1590. Console.Write("{0} ", loops[i]);
  1591. }
  1592. Console.WriteLine();
  1593. }
  1594. }
  1595.  
  1596. using System;
  1597.  
  1598. namespace Recursion
  1599. {
  1600. class Program
  1601. {
  1602. //static void Main()
  1603. //{
  1604. // Console.Write("I will give you the factorial of n. Please, enter n: ");
  1605. // int n = int.Parse(Console.ReadLine());
  1606. // int factorial = Factorial(n);
  1607. // Console.WriteLine("{0}!= {1}", n, factorial);
  1608.  
  1609. //}
  1610.  
  1611. //static int Factorial (int n)
  1612. //{
  1613. // if (n == 0) return 1;
  1614. // return Factorial(n - 1) * n;
  1615. //}
  1616.  
  1617. static void Main()
  1618. {
  1619. Console.Write(" Shte ti kaja cisloto , koeto si wywel ot konzolata na koe syotwetsta ot redicata ot cisla na Fibonacci. Molya, wywedi cislo: ");
  1620. int n = int.Parse(Console.ReadLine());
  1621. int fibonacci = 0;
  1622. fibonacci = Fibonacci(n);
  1623. Console.WriteLine(" Fibonacci ({0})= {1}", n, fibonacci);
  1624. }
  1625.  
  1626. static int Fibonacci (int n)
  1627. {
  1628. if (n <= 0) return 0;
  1629. if (n>0 && n<=2) return 1;
  1630. return Fibonacci(n - 1) + Fibonacci(n - 2);
  1631.  
  1632. }
  1633.  
  1634.  
  1635.  
  1636.  
  1637. }
  1638.  
  1639.  
  1640. }
  1641. using System;
  1642. using System.Globalization;
  1643. using System.Text;
  1644. using System.Threading;
  1645.  
  1646. class Program
  1647. {
  1648. static void Main()
  1649.  
  1650. {
  1651. Console.OutputEncoding = Encoding.UTF8;
  1652. Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US");
  1653.  
  1654.  
  1655. // Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
  1656.  
  1657.  
  1658.  
  1659.  
  1660.  
  1661. Console.WriteLine("Hello World!");
  1662. Console.WriteLine(@"C:\\Windows\\");
  1663.  
  1664. long age = 190005511;
  1665. string name = "Julian";
  1666.  
  1667.  
  1668. Console.WriteLine($"Hi! My name is {name}. I am {age} years old. ");
  1669.  
  1670. Console.WriteLine("Hi! My name is " + name + ". I am " + age + " years old.");
  1671.  
  1672. Console.WriteLine("Hi! My name is {1}. I am {1, 10:#################.0000} years old. ", name, age);
  1673.  
  1674. DateTime d = new DateTime(2019, 10, 23, 15, 30, 22);
  1675. //Console.WriteLine("{0:dd/MM/yyyy HH:mm:ss}",d);
  1676. //Console.WriteLine("{0:d.MM.yy г.}", d);
  1677. Console.WriteLine("{0:D}", d);
  1678. Console.WriteLine("{0:T}", d);
  1679. double myBalance = 213213.12345678;
  1680. Console.WriteLine("My balance is {0:C2}", myBalance);
  1681.  
  1682. Console.Write("Please enter your name: ");
  1683. string myName = Console.ReadLine();
  1684. Console.WriteLine($"Hi,{myName}! I'm glad to meet you!");
  1685.  
  1686. // Console.Write("Please enter a letter: ");
  1687. // int mySymbol = Console.Read();
  1688. // Console.WriteLine(mySymbol);
  1689.  
  1690. Console.Write("Please, enter your age: ");
  1691. int myAge = int.Parse(Console.ReadLine());
  1692. Console.WriteLine("You will be {0} years old after 10 years !", myAge + 10);
  1693.  
  1694. Console.Write("Please enter your balance:");
  1695. double myBalance1;
  1696.  
  1697. bool result= double.TryParse(Console.ReadLine(),out myBalance1);
  1698.  
  1699. Console.WriteLine((result) ? "Thank you!" : "Please enter a correct number!");
  1700. Console.Write("Enter your favourite number:");
  1701. double myNumber = Convert.ToInt32(Console.ReadLine());
  1702.  
  1703. //Console.OutputEncoding=EncodingUTF8;
  1704. Console.WriteLine("Това е кирилица:☺!");
  1705.  
  1706. string number ="100";
  1707. int fromBase = 16;
  1708. int toBase = 10;
  1709. string result1 = Convert.ToString(Convert.ToInt32(number, fromBase), toBase);
  1710. Console.WriteLine(result1);
  1711.  
  1712.  
  1713.  
  1714.  
  1715. }
  1716. }
  1717.  
  1718. using System;
  1719.  
  1720. namespace Chapter2
  1721. {
  1722. class Program
  1723. {
  1724. static void Main(string[] args)
  1725. {
  1726.  
  1727. Console.WriteLine(DateTime.Now);
  1728.  
  1729. string name1 = "Exercise 1";
  1730. Console.WriteLine(name1);
  1731.  
  1732. byte firstNum = 97;
  1733. Console.WriteLine(firstNum);
  1734.  
  1735. sbyte secondNum = 112;
  1736. Console.WriteLine(secondNum);
  1737.  
  1738. byte thirdNum = 224;
  1739. Console.WriteLine(thirdNum);
  1740.  
  1741. ushort forthNum = 1990;
  1742. Console.WriteLine(forthNum);
  1743.  
  1744. ushort fifthNum = 52130;
  1745. Console.WriteLine(fifthNum);
  1746.  
  1747. ushort sixthNum = 20000;
  1748. Console.WriteLine(sixthNum);
  1749.  
  1750. uint seventhNum = 4825932;
  1751. Console.WriteLine(seventhNum);
  1752.  
  1753. uint eigthNum = 970700000;
  1754. Console.WriteLine(eigthNum);
  1755.  
  1756. ulong ninthNum = 123456789123456789;
  1757. Console.WriteLine(ninthNum);
  1758.  
  1759. int tenthNum = -1000000;
  1760. Console.WriteLine(tenthNum);
  1761.  
  1762. short eleventhNum = -10000;
  1763. Console.WriteLine(eleventhNum);
  1764.  
  1765. sbyte twelfthNum = -115;
  1766. Console.WriteLine(twelfthNum);
  1767.  
  1768. sbyte thirtenthNum = -44;
  1769. Console.WriteLine(thirtenthNum);
  1770.  
  1771.  
  1772. string name2 = "Exercise 2";
  1773. Console.WriteLine(name2);
  1774.  
  1775. float floatY = 12.345F;
  1776. Console.WriteLine(floatY);
  1777.  
  1778. double mydoublex = 34.567839023;
  1779. Console.WriteLine(mydoublex);
  1780.  
  1781. double mydoubley = 8923.1234857;
  1782. Console.WriteLine(mydoubley);
  1783.  
  1784. decimal decnum = 3456.0911248759565421512566683467M;
  1785. Console.WriteLine(decnum);
  1786.  
  1787. string name3 = "Exercise 3 ";
  1788. Console.WriteLine(name3);
  1789.  
  1790. decimal number1 = 5.25745243896m;
  1791. decimal number2 = 9.8544531763m;
  1792. number1 += number2;
  1793. Console.WriteLine(number1.ToString("#.######"));
  1794.  
  1795. string name4 = "Exercise 4";
  1796. Console.WriteLine(name4);
  1797.  
  1798.  
  1799. int numberInHex; //declare
  1800. numberInHex = 0x100; // initiliaze
  1801. Console.WriteLine(numberInHex);
  1802.  
  1803. int intValue2 = 0x100;
  1804. Console.WriteLine(intValue2);
  1805.  
  1806. int decn, q, dn = 0, m, l;
  1807. int tmp;
  1808. int s;
  1809.  
  1810. Console.Write("\n\n");
  1811. Console.Write("Convert a number in decimal to hexadecimal:\n");
  1812. Console.Write("---------------------------------------------");
  1813. Console.Write("\n\n");
  1814.  
  1815. Console.Write("Input any Decimal number:");
  1816. decn = Convert.ToInt32(Console.ReadLine());
  1817. q = decn;
  1818. for (l = q; l > 0; l = l / 16)
  1819. {
  1820. tmp = l % 16;
  1821. if (tmp < 10)
  1822. tmp = tmp + 48;
  1823. else
  1824. tmp = tmp + 55;
  1825. dn = dn * 100 + tmp;
  1826. }
  1827. Console.Write("\nThe equivalent Hexadecimal Number : ");
  1828. for (m = dn; m > 0; m = m / 100)
  1829. {
  1830. s = m % 100;
  1831. Console.Write("{0}", (char)s);
  1832. }
  1833. Console.Write("\n\n");
  1834.  
  1835. // Store integer 256
  1836. int intValue = 256;
  1837. // Convert integer 256 as a hex in a string variable
  1838. string hexValue = intValue.ToString("X");
  1839. // Convert the hex string back to the number
  1840. int intAgain = int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber);
  1841.  
  1842. }
  1843. }
  1844. }
  1845. using System;
  1846.  
  1847. namespace Chapter4
  1848. {
  1849. class Program
  1850. {
  1851.  
  1852.  
  1853. static void Main(string[] args)
  1854. {
  1855.  
  1856. // Напишете програма, която чете от конзолата три числа от тип int и
  1857. //отпечатва тяхната сума.
  1858. // Използвайте методите Console.ReadLine() и Int32.Parse().
  1859.  
  1860.  
  1861.  
  1862. string a = Console.ReadLine();
  1863. int number1 = Convert.ToInt32(a);
  1864. string b = Console.ReadLine();
  1865. int number2 = Convert.ToInt32(b);
  1866. string c = Console.ReadLine();
  1867. int number3 = Convert.ToInt32(c);
  1868. Console.WriteLine("You entered : {0},{1},{2}", number1, number2, number3);
  1869.  
  1870.  
  1871.  
  1872.  
  1873. //2.Напишете програма, която чете от конзолата радиуса "r" на кръг и
  1874. //отпечатва неговото лице и обиколка.
  1875. //2.Използвайте константата Math.PI и добре известните формули от
  1876. //планиметрията.
  1877.  
  1878.  
  1879. // Area of Circle
  1880.  
  1881.  
  1882.  
  1883.  
  1884.  
  1885. //Perimeter and Radius of a Circle
  1886. {
  1887.  
  1888.  
  1889. Console.Write("Input the radius of the circle:");
  1890. double rad = double.Parse(Console.ReadLine());
  1891. double area = Math.PI * (Math.Pow(rad, 2));
  1892. double peri = 2 * Math.PI * rad;
  1893.  
  1894. Console.WriteLine($"The area is {area:N} and the perimeter is {peri:N}");
  1895.  
  1896. // 3 .Дадена фирма има име, адрес, телефонен номер, факс номер, уеб сайт
  1897. ////и мениджър. Мениджърът има име, фамилия и телефонен номер.
  1898. //Напишете програма, която чете информацията за фирмата и нейния мениджър и я отпечатва след това на конзолата.
  1899. //3.Форматирайте текста с Write(…) или WriteLine(…) подобно на този от
  1900. //примера с писмото, който разгледахме.
  1901. }
  1902.  
  1903. //Company's task
  1904.  
  1905. //Console.Write("Enter company's name: ");
  1906. //string companyName = Console.ReadLine();
  1907.  
  1908. //Console.Write("Enter company's adress: ");
  1909. //string companyAdress = Console.ReadLine();
  1910.  
  1911. //Console.Write("Enter company's telephone number: ");
  1912. //string cp = Console.ReadLine();
  1913. //int companyPhone = Convert.ToInt32(cp);
  1914.  
  1915. //Console.Write("Enter company's fax number: ");
  1916. //string cf = Console.ReadLine();
  1917. //int companyFax = Convert.ToInt32(cf);
  1918.  
  1919. //Console.Write("Enter company's website: ");
  1920. //string companyWebsite = Console.ReadLine();
  1921.  
  1922. //Console.Write("Enter the manager's first and last name: ");
  1923. //string managerName = Console.ReadLine();
  1924.  
  1925. //Console.Write("Enter the manager's phone number: ");
  1926. //string mp = Console.ReadLine();
  1927. //int managerPhone = Convert.ToInt32(mp);
  1928.  
  1929. //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);
  1930.  
  1931.  
  1932.  
  1933.  
  1934.  
  1935.  
  1936. Console.Write("Enter company name: ");
  1937. string compName = Console.ReadLine();
  1938. Console.Write("Enter company address: ");
  1939. string compAddr = Console.ReadLine();
  1940. Console.Write("Enter company phone number: ");
  1941. string compPhone = Console.ReadLine();
  1942. Console.Write("Enter company fax: ");
  1943. string compFax = Console.ReadLine();
  1944. Console.Write("Enter company website: ");
  1945. string compSite = Console.ReadLine();
  1946. Console.Write("Enter company manager: ");
  1947. string compManager = Console.ReadLine();
  1948. Console.Write("Enter manager first name: ");
  1949. string managerFName = Console.ReadLine();
  1950. Console.Write("Enter manager last name: ");
  1951. string managerLName = Console.ReadLine();
  1952. Console.Write("Enter manager phone: ");
  1953. string managerPhone = Console.ReadLine();
  1954.  
  1955. Console.WriteLine("Firm: Name - {0}, Address - {1}, Number - {2}, Fax - {3}, Website - {4}, Manager - {5}", compName, compAddr, compPhone, compFax, compSite, compManager);
  1956. Console.WriteLine("Manager: Name - {0} {1}, Phone - {2}", managerFName, managerLName, managerPhone);
  1957.  
  1958.  
  1959.  
  1960.  
  1961. }
  1962.  
  1963. }
  1964. }
  1965. using System;
  1966.  
  1967. namespace Chapter1
  1968. {
  1969. class Program
  1970. {
  1971. static void Main(string[] args)
  1972. {
  1973. // Ex.4
  1974. Console.WriteLine("Hello C#!");
  1975.  
  1976. // Ex.5
  1977.  
  1978. System.Console.WriteLine("Добър ден!");
  1979.  
  1980. // Ex.6
  1981.  
  1982. System.Console.WriteLine("Julain Zhelezchev");
  1983.  
  1984. // Ex.7
  1985.  
  1986. System.Console.WriteLine("1");
  1987. System.Console.WriteLine("101");
  1988. System.Console.WriteLine("1001");
  1989.  
  1990. // Ex.8
  1991.  
  1992. System.Console.WriteLine(System.DateTime.Now);
  1993.  
  1994.  
  1995.  
  1996.  
  1997.  
  1998.  
  1999.  
  2000.  
  2001. }
  2002. }
  2003. }
  2004. using System;
  2005.  
  2006. namespace Problem1
  2007.  
  2008. {
  2009. class Program
  2010. {
  2011. static void Main()
  2012. {
  2013. // Напишете програма, която отпечатва на конзолата числата от 1 до N.
  2014. //Числото N трябва да се чете от стандартния вход.
  2015. // 1.Използвайте for цикъл.
  2016.  
  2017.  
  2018. Console.Write("Enter n = ");
  2019.  
  2020. int n = int.Parse(Console.ReadLine());
  2021.  
  2022. for (int i = 1; i < n; i++)
  2023.  
  2024. {
  2025.  
  2026. Console.WriteLine(i);
  2027.  
  2028. }
  2029.  
  2030.  
  2031.  
  2032.  
  2033.  
  2034. }
  2035. }
  2036.  
  2037.  
  2038.  
  2039.  
  2040.  
  2041. }
  2042. using System;
  2043.  
  2044. namespace Problem2
  2045. {
  2046. class Program
  2047. {
  2048. static void Main()
  2049. {
  2050. // Напишете програма, която отпечатва на конзолата числата от 1 до N, които не се делят едновременно на 3 и 7.
  2051. //Числото N да се чете от стандартния вход.
  2052. // Използвайте for цикъл и оператора % за намиране на остатък при целочислено деление.
  2053. //Едно число num не се дели на 3 и на 7 едновременно, ако(num % (3 * 7) == 0).
  2054.  
  2055. Console.WriteLine("Please enter your number: ");
  2056. int n = int.Parse(Console.ReadLine());
  2057.  
  2058. for (int i = 1; i <= n; i++)
  2059. {
  2060. if (i % 3 == 0)
  2061. {
  2062. continue;
  2063. }
  2064. else if (i % 7 == 0)
  2065. {
  2066. continue;
  2067. }
  2068. Console.WriteLine("{0} ", i);
  2069. }
  2070.  
  2071. }
  2072. }
  2073. }
  2074.  
  2075. using System;
  2076.  
  2077. namespace Problem1_
  2078. {
  2079. class Program
  2080. {
  2081. static void Main(string[] args)
  2082. {
  2083. Console.Write("Enter first number: ");
  2084. int a = Int32.Parse(Console.ReadLine());
  2085. Console.Write("Enter second number: ");
  2086. int b = Int32.Parse(Console.ReadLine());
  2087.  
  2088. if (a > b)
  2089. {
  2090. a = a + b;
  2091. b = a - b;
  2092. a = a - b;
  2093. }
  2094.  
  2095. Console.WriteLine("First number - {0}, Second number - {1}.", a, b);
  2096.  
  2097. }
  2098.  
  2099.  
  2100. }
  2101. }
  2102. using System;
  2103.  
  2104. namespace Problem2
  2105. {
  2106. class Program
  2107. {
  2108. static void Main()
  2109. {
  2110. 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.");
  2111. Console.Write(" Please,enter the first number: ");
  2112. int a = Int32.Parse(Console.ReadLine());
  2113. Console.Write(" Please, enter the second number: ");
  2114. int b = Int32.Parse(Console.ReadLine());
  2115. Console.Write(" Please, enter the third number: ");
  2116. int c = Int32.Parse(Console.ReadLine());
  2117.  
  2118. if (a < 0 & b < 0 & c < 0)
  2119. {
  2120. Console.WriteLine("The sign is -");
  2121. }
  2122. else if (a < 0 & b > 0 & c > 0)
  2123. {
  2124. Console.WriteLine("The sign is - ");
  2125. }
  2126. else if (c < 0 & a > 0 & b > 0)
  2127. {
  2128. Console.WriteLine("The sign is -");
  2129. }
  2130.  
  2131. else if (b < 0& c > 0 & a > 0)
  2132. {
  2133. Console.WriteLine("The sign is - ");
  2134. }
  2135.  
  2136. else if (a > 0 & b > 0 & c > 0)
  2137. {
  2138. Console.WriteLine("The sign is + ");
  2139. }
  2140. else if (a <0 & b <0 & c>0)
  2141.  
  2142. {
  2143. Console.WriteLine("The sign is + ");
  2144. }
  2145. else if (b <0 & c<0 & a>0)
  2146. {
  2147. Console.WriteLine("The sign is + ");
  2148. }
  2149.  
  2150. else if (c<0 & a<0 & b>0)
  2151. {
  2152. Console.WriteLine("The sign is + ");
  2153. }
  2154.  
  2155. else if (a>=0 & b>=0 & c>=0)
  2156. Console.WriteLine("The result is zero");
  2157.  
  2158.  
  2159.  
  2160.  
  2161.  
  2162.  
  2163.  
  2164.  
  2165. }
  2166. }
  2167. }
  2168. using System;
  2169.  
  2170. namespace Problem3
  2171. {
  2172. class Program
  2173. {
  2174. static void Main(string[] args)
  2175. {
  2176. Console.Write("Enter first number: ");
  2177. int a = Int32.Parse(Console.ReadLine());
  2178. Console.Write("Enter second number: ");
  2179. int b = Int32.Parse(Console.ReadLine());
  2180. Console.Write("Enter third number: ");
  2181. int c = Int32.Parse(Console.ReadLine());
  2182.  
  2183. if (a > b)
  2184. if (a > c) Console.WriteLine("A is the biggest");
  2185. else if (a < c) Console.WriteLine("C is the biggest");
  2186. else Console.WriteLine("A and C are the biggest");
  2187. else if (a < b)
  2188. if (b > c) Console.WriteLine("B is the biggest");
  2189. else if (b < c) Console.WriteLine("C is the biggest");
  2190. else Console.WriteLine("B and C are the biggest");
  2191. else if (a == b)
  2192. if (a == c) Console.WriteLine("All are equal");
  2193. else if (a < c) Console.WriteLine("C is the biggest");
  2194. else Console.WriteLine("A and B are the biggest");
  2195. }
  2196. }
  2197.  
  2198. }
  2199. using System;
  2200.  
  2201. namespace Problem3
  2202. {
  2203. class Program
  2204. {
  2205. static void Main()
  2206. {
  2207. //Напишете израз, който да проверява дали третата цифра(отдясно на ляво) на дадено цяло число е 7.
  2208. // Разделете числото на 100 и го запишете в нова променлива. Нея разделете на 10 и вземете остатъкът.Остатъкът от делението на 10 е третата цифра от първоначалното число. Проверете равна ли е на 7.
  2209.  
  2210. int number = 45764;
  2211. bool isSeven = (number / 100) % 10 == 7 ? true : false;
  2212. Console.WriteLine("Third digit of {0} is 7", number, isSeven);
  2213.  
  2214. }
  2215. }
  2216. }
  2217. using System;
  2218.  
  2219. namespace Problem1
  2220. {
  2221. class Program
  2222. {
  2223. static void Main()
  2224. {
  2225.  
  2226.  
  2227. // 1.Напишете израз, който да проверява дали дадено цяло число е четно или нечетно.
  2228.  
  2229. // Вземете остатъкът от деленето на числото на 2 и проверете дали е 0 или 1(съответно числото е четно или нечетно).Използвайте оператора % за пресмятане на остатък от целочислено деление.
  2230.  
  2231.  
  2232. int number = 23;
  2233. bool even = number % 2 == 0 ? true : false;
  2234. Console.WriteLine("{0} is even? {1}", number, even);
  2235.  
  2236. }
  2237. }
  2238. }
  2239. using System;
  2240.  
  2241. namespace Problem2
  2242. {
  2243. class Program
  2244. {
  2245. static void Main()
  2246. {
  2247. // 2.Напишете булев израз, който да проверява дали дадено цяло число се дели на 5 и на 7 без остатък.
  2248.  
  2249. // Ползвайте логическо "И"(оператора &&) и операцията % за остатък при деление.Можете да решите задачата и чрез само една проверка – за деление на 35(помислете защо).
  2250.  
  2251.  
  2252. int number = 36;
  2253. bool divisible = number % 35 == 0 ? true : false;
  2254. Console.WriteLine("{0} is divisible by both 5 and 7? {1}", number, divisible);
  2255.  
  2256. }
  2257. }
  2258. }
  2259. using System;
  2260.  
  2261. namespace Problem3
  2262. {
  2263. class Program
  2264. {
  2265. static void Main()
  2266. {
  2267. //Напишете израз, който да проверява дали третата цифра(отдясно на ляво) на дадено цяло число е 7.
  2268. // Разделете числото на 100 и го запишете в нова променлива. Нея разделете на 10 и вземете остатъкът.Остатъкът от делението на 10 е третата цифра от първоначалното число. Проверете равна ли е на 7.
  2269.  
  2270. int number = 45764;
  2271. bool isSeven = (number / 100) % 10 == 7 ? true : false;
  2272. Console.WriteLine("Third digit of {0} is 7", number, isSeven);
  2273.  
  2274. }
  2275. }
  2276. }
  2277. using System;
  2278.  
  2279. namespace Problem4
  2280. {
  2281. class Program
  2282. {
  2283. static void Main()
  2284. {
  2285. // Да се напише програма, която преобразува десетично число в двоично.
  2286. // Правилото е "делим на 2 и долепяме остатъците в обратен ред".
  2287. //За делене с остатък използваме оператора %.Можете да се изхитрите,
  2288. //като използвате Convert.ToString(numDecimal, 2).
  2289.  
  2290.  
  2291. String number = "100";
  2292. int fromBase = 10;
  2293. int toBase = 2;
  2294.  
  2295. String result = Convert.ToString(Convert.ToInt32(number, fromBase), toBase);
  2296.  
  2297. Console.WriteLine(result); // result 1100100
  2298.  
  2299.  
  2300. / Convert to binary system
  2301. Console.Write("Please, enter a number to convert to binary: ");
  2302. // with 340282366920938000000000000000000000000
  2303. // System.OverflowException: Value was either too large or too small for an Int32.
  2304. int number2Convert = int.Parse(Console.ReadLine());
  2305. int[] binaryNumber = new int[128]; // the default value is 0
  2306. int digitCounter = 127;
  2307. while (number2Convert > 0 && digitCounter > 0)
  2308. {
  2309. binaryNumber[digitCounter] = number2Convert % 2;
  2310. digitCounter--;
  2311. number2Convert /= 2;
  2312. Console.WriteLine(number2Convert);
  2313. }
  2314. foreach (var digit in binaryNumber)
  2315. {
  2316. Console.Write(digit);
  2317. }
  2318. Console.WriteLine();
  2319. Console.WriteLine(Math.Pow(2, 128)); // 3.40282366920938E+38
  2320. // Console.WriteLine("{0,10:N}", Math.Pow(2, 128)); // 340,282,366,920,938,000,000,000,000,000,000,000,000.00
  2321. // Console.WriteLine("{0,10:D}", Math.Pow(2, 128)); // Exception
  2322. Console.WriteLine("{0,10:F0}", Math.Pow(2, 128)); // 340282366920938000000000000000000000000
  2323.  
  2324.  
  2325.  
  2326.  
  2327. }
  2328. }
  2329. }
  2330. using System;
  2331.  
  2332. namespace Problem1
  2333. {
  2334. class Program
  2335. {
  2336. static void Main()
  2337. {
  2338.  
  2339. // 1.Превърнете числата 151, 35, 43, 251, 1023 и 1024 в двоична
  2340. // бройна система.
  2341. // Използвайте методите за превръщане от една бройна система в
  2342. //друга.Можете да сверите резултатите си с калкулатора на Windows,
  2343. //който поддържа работа с бройни системи след превключване в режим
  2344. //"Programmer".Резултатите са 10010111, 100011, 11111011, 1111111111 и
  2345. //10000000000.
  2346.  
  2347.  
  2348. // 151:2 = 75 остатък 1;
  2349. // 75:2 = 37 остатък 1;
  2350. // 37:2= 18 остатък 1;
  2351. // 18:2= 9 остатък 0;
  2352. // 9:2= 4 остатък 1;
  2353. // 4:2=2 остатък 0;
  2354. // 2:2=1 остатък 0;
  2355. // 1:2=0 остатък 1;
  2356.  
  2357. //151(10)=10010111(2)
  2358.  
  2359. // 35:2=17 остатък 1;
  2360. // 17:2= 8 остатък 1;
  2361. // 8:2= 4 остатък 0;
  2362. // 4:2= 2 остатък 0;
  2363. // 2:2= 1 остатък 0;
  2364. // 1:2=0 остатък 1;
  2365.  
  2366. // 32(10)= 100011(2)
  2367.  
  2368. //43:2= 21 остатък 1;
  2369. //21:2=10 остатък 1;
  2370. //10:2=5 остатък 0;
  2371. //5:2=2 остатък 1;
  2372. //2:2=1 остатък 0;
  2373. //1:2=0 остатък 1;
  2374.  
  2375. // 43(10)=101011(2)
  2376.  
  2377. //251:2= 125 остатък 1;
  2378. //125:2= 62 остатък 1;
  2379. //62:2= 31 остатък 0;
  2380. //31:2= 15 остатък 1;
  2381. //15:2= 7 остатък 1;
  2382. //7:2 = 3 остатък 1;
  2383. //3:2= 1 остатък 1;
  2384. //1:2=0 остатък 1;
  2385.  
  2386. //251(10)= 11111011(2)
  2387.  
  2388. //1023:2= 511 остатък 1;
  2389. //511:2= 255 остатък 1;
  2390. //255:2= 127 остатък 1;
  2391. //127:2= 63 остатък 1;
  2392. //63:2= 31 остатък 1;
  2393. //31:2= 15 остатък 1;
  2394. //15:2 = 7 остатък 1;
  2395. //7:2= 3 остатък 1;
  2396. //3:2=1 остатък 1;
  2397. //1:2=0 остатък 1;
  2398.  
  2399. //1023(10)= 1111111111(2)
  2400.  
  2401. //1024:2= 512 остатък 0;
  2402. //512:2= 256 остатък 0;
  2403. //256:2= 128 остатък 0;
  2404. //128:2= 64 остатък 0;
  2405. //64:2= 32 остатък 0;
  2406. //32:2= 16 остатък 0;
  2407. //16:2= 8 остатък 0;
  2408. //8:2= 4 остатък 0;
  2409. //4:2=2 остатък 0;
  2410. //2:2=1 остатък 0;
  2411. //1:2= 0 остатък 1;
  2412.  
  2413. //1024(10)= 10000000000(2)
  2414.  
  2415.  
  2416.  
  2417. }
  2418. }
  2419. }
  2420. using System;
  2421.  
  2422. namespace Problem2
  2423. {
  2424. class Program
  2425. {
  2426. static void Main()
  2427. {
  2428. // Превърнете числото 1111010110011110(2) в шестнадесетична и в десетична бройна система.
  2429. //Погледнете упътването за предходната задача.Резултат: F59E(16) и
  2430. //62878(10).
  2431.  
  2432. // 1111 0101 1001 1110
  2433. // 15 = F; 5 9 14=E
  2434.  
  2435.  
  2436.  
  2437. // 1111010110011110(2) = F59E(16);
  2438.  
  2439. // 1111010110011110
  2440. //(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=
  2441. // = 32,768+ 16,384 + 8,192 + 4,096 + 1,024 + 256 + 128 + 16 + 8 + 4 + 2 = 62878(10);
  2442.  
  2443.  
  2444.  
  2445.  
  2446.  
  2447.  
  2448.  
  2449.  
  2450.  
  2451. }
  2452.  
  2453.  
  2454.  
  2455.  
  2456.  
  2457.  
  2458.  
  2459. }
  2460. }
  2461. using System;
  2462.  
  2463. namespace Problem3
  2464. {
  2465. class Program
  2466. {
  2467. static void Main()
  2468. {
  2469.  
  2470. //Превърнете шестнайсетичните числа 2A3E, FA, FFFF, 5A0E9 в
  2471. //двоична и десетична бройна система.
  2472. // Погледнете упътването за предходната задача.Резултати:
  2473. //FA(16) = 250(10) = 11111010(2), 2A3E(16) = 10814(10) =
  2474. //10101000111110(2), FFFF(16) = 65535(10) = 1111111111111111(2), 5A0E9(16) =
  2475. //368873(10) = 1011010000011101001(2).
  2476.  
  2477. 2A3E(16) 16→2;
  2478. 2 A=10 3 E=14
  2479. 0010 1010 0011 1110 = 0010101000111110(2);
  2480.  
  2481. 2A3E(16) 16→10;
  2482. Е*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)
  2483.  
  2484.  
  2485. FA(16) 16→2;
  2486. F=15 A=10
  2487. 1111 1010 = 11111010(2);
  2488.  
  2489. FA(16) 16→10;
  2490. 15*16^1+ 10*16^0= 240+ 10 =250(10)
  2491.  
  2492.  
  2493. FFFF(16) 16→2;
  2494. F = 15
  2495. 1111 1111 1111 1111 = 1111111111111111(2);
  2496.  
  2497. FFFF(16) 16→10
  2498. 15 * 16 ^ 0 + 15 * 16 ^ 1 + 15 * 16 ^ 2 + 15 * 16 ^ 3 = 15 + 240 + 3840 + 61440 = 65535(10);
  2499.  
  2500.  
  2501. 5A0E9(16) 16→2;
  2502. 5 A=10 0 E=14 9
  2503. 0101 1010 0000 1110 1001 = 01011010000011101001(2);
  2504.  
  2505. 5A0E9(16) 16→10;
  2506. 9 * 16 ^ 0 + 14 * 16 ^ 1 + 0 * 16 ^ 2 + 10 * 16 ^ 3 + 5 * 16 ^ 4 = 9 + 224 + 0 + 40960 + 327680 = 368873(10);
  2507.  
  2508.  
  2509.  
  2510.  
  2511.  
  2512.  
  2513.  
  2514.  
  2515.  
  2516.  
  2517.  
  2518.  
  2519.  
  2520.  
  2521.  
  2522.  
  2523. }
  2524.  
  2525.  
  2526. }
  2527. }
  2528. using System;
  2529.  
  2530. namespace Problem4
  2531. {
  2532. class Program
  2533. {
  2534. static void Main()
  2535. {
  2536. // Да се напише програма, която преобразува десетично число в двоично.
  2537. // Правилото е "делим на 2 и долепяме остатъците в обратен ред".
  2538. //За делене с остатък използваме оператора %.Можете да се изхитрите,
  2539. //като използвате Convert.ToString(numDecimal, 2).
  2540.  
  2541.  
  2542. String number = "100";
  2543. int fromBase = 10;
  2544. int toBase = 2;
  2545.  
  2546. String result = Convert.ToString(Convert.ToInt32(number, fromBase), toBase);
  2547.  
  2548. Console.WriteLine(result); // result 1100100
  2549.  
  2550.  
  2551. / Convert to binary system
  2552. Console.Write("Please, enter a number to convert to binary: ");
  2553. // with 340282366920938000000000000000000000000
  2554. // System.OverflowException: Value was either too large or too small for an Int32.
  2555. int number2Convert = int.Parse(Console.ReadLine());
  2556. int[] binaryNumber = new int[128]; // the default value is 0
  2557. int digitCounter = 127;
  2558. while (number2Convert > 0 && digitCounter > 0)
  2559. {
  2560. binaryNumber[digitCounter] = number2Convert % 2;
  2561. digitCounter--;
  2562. number2Convert /= 2;
  2563. Console.WriteLine(number2Convert);
  2564. }
  2565. foreach (var digit in binaryNumber)
  2566. {
  2567. Console.Write(digit);
  2568. }
  2569. Console.WriteLine();
  2570. Console.WriteLine(Math.Pow(2, 128)); // 3.40282366920938E+38
  2571. // Console.WriteLine("{0,10:N}", Math.Pow(2, 128)); // 340,282,366,920,938,000,000,000,000,000,000,000,000.00
  2572. // Console.WriteLine("{0,10:D}", Math.Pow(2, 128)); // Exception
  2573. Console.WriteLine("{0,10:F0}", Math.Pow(2, 128)); // 340282366920938000000000000000000000000
  2574.  
  2575.  
  2576.  
  2577.  
  2578. }
  2579. }
  2580. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement