Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace AdMessege
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int n = int.Parse(Console.ReadLine());
  14. Console.WriteLine("product");
  15. }
  16. }
  17. }
  18. //----------------------------------2---------------------------------
  19. using System;
  20. using System.Collections.Generic;
  21. using System.Linq;
  22.  
  23. namespace LecturePractice
  24. {
  25. public class Program
  26. {
  27. public class Article
  28. {
  29. public string Title { get; set; }
  30.  
  31. public string Content { get; set; }
  32.  
  33. public string Author { get; set; }
  34. }
  35. public static void Main()
  36. {
  37. var inputText = Console.ReadLine()
  38. .Split(", ")
  39. .ToList();
  40.  
  41. var number = int.Parse(Console.ReadLine());
  42.  
  43. var article = new Article
  44. {
  45. Title = inputText[0],
  46. Content = inputText[1],
  47. Author = inputText[2]
  48. };
  49.  
  50. for (int i = 0; i < number; i++)
  51. {
  52. var newInput = Console.ReadLine()
  53. .Split(':')
  54. .Select(s => s.Trim())
  55. .ToList();
  56.  
  57. if (newInput[0] == "Edit")
  58. {
  59. article.Content = newInput[1];
  60. }
  61. else if (newInput[0] == "ChangeAuthor")
  62. {
  63. article.Author = newInput[1];
  64. }
  65. else if (newInput[0] == "Rename")
  66. {
  67. article.Title = newInput[1];
  68. }
  69. }
  70.  
  71. Console.WriteLine($"{article.Title} - {article.Content}: {article.Author}");
  72. }
  73. }
  74. }
  75. //----------------------------------------3------------------------------------------
  76. using System;
  77. using System.Collections.Generic;
  78. using System.Linq;
  79.  
  80. namespace _03Articles2._0
  81. {
  82. public class Article
  83. {
  84. public Article(string title, string content, string author)
  85. {
  86. Title = title;
  87. Content = content;
  88. Author = author;
  89. }
  90.  
  91. public string Title { get; set; }
  92. public string Content { get; set; }
  93. public string Author { get; set; }
  94.  
  95. public override string ToString()
  96. {
  97. return $"{Title} - {Content}: {Author}";
  98. }
  99. }
  100.  
  101. class Program
  102. {
  103. static void Main(string[] args)
  104. {
  105. int countCommands = int.Parse(Console.ReadLine());
  106. var articles = new List<Article>();
  107.  
  108. for (int i = 0; i < countCommands; i++)
  109. {
  110. string[] splittedCommand = Console.ReadLine()
  111. .Split(", ");
  112.  
  113. string title = splittedCommand[0];
  114. string content = splittedCommand[1];
  115. string author = splittedCommand[2];
  116.  
  117. var article = new Article(title, content, author);
  118.  
  119. articles.Add(article);
  120. }
  121. string orderBy = Console.ReadLine();
  122.  
  123. if (orderBy == "title")
  124. {
  125. articles = articles.OrderBy(x => x.Title)
  126. .ToList();
  127. }
  128. else if (orderBy == "content")
  129. {
  130. articles = articles.OrderBy(x => x.Content)
  131. .ToList();
  132. }
  133. else if (orderBy == "author")
  134. {
  135. articles = articles.OrderBy(x => x.Author)
  136. .ToList();
  137. }
  138. Console.WriteLine(string.Join(Environment.NewLine, articles));
  139. }
  140. }
  141. }
  142. //----------------------------------4-------------------------------------------
  143. using System;
  144. using System.Collections.Generic;
  145. using System.Linq;
  146.  
  147. namespace _04._Students
  148. {
  149. class Program
  150. {
  151. static void Main(string[] args)
  152. {
  153. List<Student> articles = new List<Student>();
  154. int n = int.Parse(Console.ReadLine());
  155.  
  156. for (int i = 0; i < n; i++)
  157. {
  158. string[] data = Console.ReadLine().Split(" ");
  159. articles.Add(new Student(data));
  160. }
  161. articles = articles.OrderByDescending(x => x.Grade).ToList();
  162. articles.ForEach(x => Console.WriteLine(x.ToString()));
  163. }
  164. }
  165. class Student
  166. {
  167. public string FirstName { get; set; }
  168. public string SecondName { get; set; }
  169. public double Grade { get; set; }
  170.  
  171. public Student(string[] data)
  172. {
  173. FirstName = data[0];
  174. SecondName = data[1];
  175. Grade = double.Parse(data[2]);
  176. }
  177.  
  178. public override string ToString()
  179. {
  180. return $"{FirstName} {SecondName}: {Grade:F2}";
  181. }
  182. }
  183. }
  184. //-------------------------------5------------------------------------
  185. using System;
  186. using System.Collections.Generic;
  187. using System.Linq;
  188.  
  189. namespace TeamworkProjects
  190. {
  191. class Team
  192. {
  193. public string TeamName { get; set; }
  194. public string CreatorName { get; set; }
  195. public List<string> Members { get; set; }
  196. }
  197. class Program
  198. {
  199. static void Main(string[] args)
  200. {
  201. int teamsCount = int.Parse(Console.ReadLine());
  202. List<Team> teams = new List<Team>();
  203. for (int i = 0; i < teamsCount; i++)
  204. {
  205. string[] newTeam = Console.ReadLine().Split('-').ToArray();
  206. List<string> membersList = new List<string>();
  207. Team team = new Team();
  208. team.TeamName = newTeam[1];
  209. team.CreatorName = newTeam[0];
  210. team.Members = membersList;
  211. if (!teams.Select(x => x.TeamName).Contains(team.TeamName))
  212. {
  213. if (!teams.Select(x => x.CreatorName).Contains(team.CreatorName))
  214. {
  215. teams.Add(team);
  216. Console.WriteLine("Team {0} has been created by {1}!", newTeam[1], newTeam[0]);
  217. }
  218. else
  219. {
  220. Console.WriteLine("{0} cannot create another team!", team.CreatorName);
  221. }
  222. }
  223. else
  224. {
  225. Console.WriteLine("Team {0} was already created!", team.TeamName);
  226. }
  227. }
  228.  
  229. string teamRegistration = Console.ReadLine();
  230.  
  231. while (!teamRegistration.Equals("end of assignment"))
  232. {
  233. var split = teamRegistration.Split(new char[] { '-', '>' }).ToArray();
  234. string newUser = split[0];
  235. string teamName = split[2];
  236. if (!teams.Select(x => x.TeamName).Contains(teamName))
  237. {
  238. Console.WriteLine("Team {0} does not exist!", teamName);
  239. }
  240. else if (teams.Select(x => x.Members).Any(x => x.Contains(newUser)) || teams.Select(x => x.CreatorName).Contains(newUser))
  241. {
  242. Console.WriteLine("Member {0} cannot join team {1}!", newUser, teamName);
  243. }
  244. else
  245. {
  246. int teamToJoinIndex = teams.FindIndex(x => x.TeamName == teamName);
  247. teams[teamToJoinIndex].Members.Add(newUser);
  248. }
  249.  
  250. teamRegistration = Console.ReadLine();
  251. }
  252.  
  253. var teamsToDisband = teams.OrderBy(x => x.TeamName).Where(x => x.Members.Count == 0);
  254. var fullTeams = teams.
  255. OrderByDescending(x => x.Members.Count).
  256. ThenBy(x => x.TeamName).
  257. Where(x => x.Members.Count > 0);
  258.  
  259. foreach (var team in fullTeams)
  260. {
  261. Console.WriteLine($"{team.TeamName}");
  262. Console.WriteLine($"- {team.CreatorName}");
  263. foreach (var member in team.Members.OrderBy(x => x))
  264. {
  265. Console.WriteLine($"-- {member}");
  266. }
  267. }
  268.  
  269. Console.WriteLine("Teams to disband:");
  270. foreach (var item in teamsToDisband)
  271. {
  272. Console.WriteLine(item.TeamName);
  273. }
  274.  
  275. }
  276. }
  277.  
  278. }
  279. //---------------------------------------6--------------------------------------------
  280. using System;
  281. using System.Collections.Generic;
  282. using System.Linq;
  283.  
  284. namespace _06._Vehicle_Catalogue
  285. {
  286. public class Vehicle_Catalogue
  287. {
  288. public static void Main()
  289. {
  290. List<Vehicle> catalogue = new List<Vehicle>();
  291.  
  292. while (true)
  293. {
  294. string[] inputTokens = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
  295. if (inputTokens[0] == "End")
  296. {
  297. break;
  298. }
  299.  
  300. string type = inputTokens[0].ToLower();
  301. string model = inputTokens[1];
  302. string color = inputTokens[2].ToLower();
  303. int horsePower = int.Parse(inputTokens[3]);
  304. var currentVehicle = new Vehicle(type, model, color, horsePower);
  305. catalogue.Add(currentVehicle);
  306. }
  307.  
  308. while (true)
  309. {
  310. string model = Console.ReadLine();
  311. if (model == "Close the Catalogue")
  312. {
  313. break;
  314. }
  315.  
  316. Console.WriteLine(catalogue.Find(x => x.Model == model));
  317. }
  318.  
  319. var onlyCars = catalogue.Where(x => x.Type == "car").ToList();
  320. var onlyTrucks = catalogue.Where(x => x.Type == "truck").ToList();
  321. double totalCarsHorsepower = 0;
  322. double totalTrucksHorsepower = 0;
  323.  
  324. foreach (var car in onlyCars)
  325. {
  326. totalCarsHorsepower += car.HorsePower;
  327. }
  328.  
  329. foreach (var truck in onlyTrucks)
  330. {
  331. totalTrucksHorsepower += truck.HorsePower;
  332. }
  333.  
  334. double averageCarsHorsepower = totalCarsHorsepower / onlyCars.Count;
  335. double averageTrucksHorsepower = totalTrucksHorsepower / onlyTrucks.Count;
  336.  
  337. if (onlyCars.Count > 0)
  338. {
  339. Console.WriteLine($"Cars have average horsepower of: {averageCarsHorsepower:f2}.");
  340.  
  341. }
  342. else
  343. {
  344. Console.WriteLine($"Cars have average horsepower of: {0:f2}.");
  345. }
  346.  
  347. if (onlyTrucks.Count > 0)
  348. {
  349. Console.WriteLine($"Trucks have average horsepower of: {averageTrucksHorsepower:f2}.");
  350. }
  351. else
  352. {
  353. Console.WriteLine($"Trucks have average horsepower of: {0:f2}.");
  354. }
  355. }
  356. }
  357.  
  358. public class Vehicle
  359. {
  360. public Vehicle(string type, string model, string color, int horsePower)
  361. {
  362. this.Type = type;
  363. this.Model = model;
  364. this.Color = color;
  365. this.HorsePower = horsePower;
  366. }
  367.  
  368. public string Type { get; set; }
  369. public string Model { get; set; }
  370. public string Color { get; set; }
  371. public int HorsePower { get; set; }
  372.  
  373. public override string ToString()
  374. {
  375. string vehicleStr = $"Type: {(this.Type == "car" ? "Car" : "Truck")}{Environment.NewLine}" +
  376. $"Model: {this.Model}{Environment.NewLine}" +
  377. $"Color: {this.Color}{Environment.NewLine}" +
  378. $"Horsepower: {this.HorsePower}";
  379.  
  380. return vehicleStr;
  381. }
  382. }
  383. }
  384. //--------------------------------------------7--------------------------------------------------
  385. using System;
  386. using System.Collections.Generic;
  387. using System.Linq;
  388.  
  389. namespace Order_by_Age
  390. {
  391. class Person
  392. {
  393. public string Name { get; set; }
  394.  
  395. public int ID { get; set; }
  396.  
  397. public int Age { get; set; }
  398. }
  399. class Program
  400. {
  401. public static void Main(string[] args)
  402. {
  403. List<string> tokens = Console.ReadLine().Split().ToList();
  404. List<Person> list = new List<Person>();
  405.  
  406. while (tokens[0] != "End")
  407. {
  408.  
  409. string name = tokens[0];
  410. int id = int.Parse(tokens[1]);
  411. int age = int.Parse(tokens[2]);
  412. Person person = new Person()
  413. {
  414. Name = name,
  415. ID = id,
  416. Age = age
  417. };
  418.  
  419. list.Add(person);
  420.  
  421. tokens = Console.ReadLine().Split().ToList();
  422.  
  423. }
  424.  
  425. var result = list.OrderBy(person => person.Age);
  426. foreach (var item in result)
  427. {
  428. Console.WriteLine($"{item.Name} with ID: {item.ID} is {item.Age} years old.");
  429. }
  430. }
  431. }
  432. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement