Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace AdMessege
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- Console.WriteLine("product");
- }
- }
- }
- //----------------------------------2---------------------------------
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace LecturePractice
- {
- public class Program
- {
- public class Article
- {
- public string Title { get; set; }
- public string Content { get; set; }
- public string Author { get; set; }
- }
- public static void Main()
- {
- var inputText = Console.ReadLine()
- .Split(", ")
- .ToList();
- var number = int.Parse(Console.ReadLine());
- var article = new Article
- {
- Title = inputText[0],
- Content = inputText[1],
- Author = inputText[2]
- };
- for (int i = 0; i < number; i++)
- {
- var newInput = Console.ReadLine()
- .Split(':')
- .Select(s => s.Trim())
- .ToList();
- if (newInput[0] == "Edit")
- {
- article.Content = newInput[1];
- }
- else if (newInput[0] == "ChangeAuthor")
- {
- article.Author = newInput[1];
- }
- else if (newInput[0] == "Rename")
- {
- article.Title = newInput[1];
- }
- }
- Console.WriteLine($"{article.Title} - {article.Content}: {article.Author}");
- }
- }
- }
- //----------------------------------------3------------------------------------------
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _03Articles2._0
- {
- public class Article
- {
- public Article(string title, string content, string author)
- {
- Title = title;
- Content = content;
- Author = author;
- }
- public string Title { get; set; }
- public string Content { get; set; }
- public string Author { get; set; }
- public override string ToString()
- {
- return $"{Title} - {Content}: {Author}";
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- int countCommands = int.Parse(Console.ReadLine());
- var articles = new List<Article>();
- for (int i = 0; i < countCommands; i++)
- {
- string[] splittedCommand = Console.ReadLine()
- .Split(", ");
- string title = splittedCommand[0];
- string content = splittedCommand[1];
- string author = splittedCommand[2];
- var article = new Article(title, content, author);
- articles.Add(article);
- }
- string orderBy = Console.ReadLine();
- if (orderBy == "title")
- {
- articles = articles.OrderBy(x => x.Title)
- .ToList();
- }
- else if (orderBy == "content")
- {
- articles = articles.OrderBy(x => x.Content)
- .ToList();
- }
- else if (orderBy == "author")
- {
- articles = articles.OrderBy(x => x.Author)
- .ToList();
- }
- Console.WriteLine(string.Join(Environment.NewLine, articles));
- }
- }
- }
- //----------------------------------4-------------------------------------------
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _04._Students
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<Student> articles = new List<Student>();
- int n = int.Parse(Console.ReadLine());
- for (int i = 0; i < n; i++)
- {
- string[] data = Console.ReadLine().Split(" ");
- articles.Add(new Student(data));
- }
- articles = articles.OrderByDescending(x => x.Grade).ToList();
- articles.ForEach(x => Console.WriteLine(x.ToString()));
- }
- }
- class Student
- {
- public string FirstName { get; set; }
- public string SecondName { get; set; }
- public double Grade { get; set; }
- public Student(string[] data)
- {
- FirstName = data[0];
- SecondName = data[1];
- Grade = double.Parse(data[2]);
- }
- public override string ToString()
- {
- return $"{FirstName} {SecondName}: {Grade:F2}";
- }
- }
- }
- //-------------------------------5------------------------------------
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace TeamworkProjects
- {
- class Team
- {
- public string TeamName { get; set; }
- public string CreatorName { get; set; }
- public List<string> Members { get; set; }
- }
- class Program
- {
- static void Main(string[] args)
- {
- int teamsCount = int.Parse(Console.ReadLine());
- List<Team> teams = new List<Team>();
- for (int i = 0; i < teamsCount; i++)
- {
- string[] newTeam = Console.ReadLine().Split('-').ToArray();
- List<string> membersList = new List<string>();
- Team team = new Team();
- team.TeamName = newTeam[1];
- team.CreatorName = newTeam[0];
- team.Members = membersList;
- if (!teams.Select(x => x.TeamName).Contains(team.TeamName))
- {
- if (!teams.Select(x => x.CreatorName).Contains(team.CreatorName))
- {
- teams.Add(team);
- Console.WriteLine("Team {0} has been created by {1}!", newTeam[1], newTeam[0]);
- }
- else
- {
- Console.WriteLine("{0} cannot create another team!", team.CreatorName);
- }
- }
- else
- {
- Console.WriteLine("Team {0} was already created!", team.TeamName);
- }
- }
- string teamRegistration = Console.ReadLine();
- while (!teamRegistration.Equals("end of assignment"))
- {
- var split = teamRegistration.Split(new char[] { '-', '>' }).ToArray();
- string newUser = split[0];
- string teamName = split[2];
- if (!teams.Select(x => x.TeamName).Contains(teamName))
- {
- Console.WriteLine("Team {0} does not exist!", teamName);
- }
- else if (teams.Select(x => x.Members).Any(x => x.Contains(newUser)) || teams.Select(x => x.CreatorName).Contains(newUser))
- {
- Console.WriteLine("Member {0} cannot join team {1}!", newUser, teamName);
- }
- else
- {
- int teamToJoinIndex = teams.FindIndex(x => x.TeamName == teamName);
- teams[teamToJoinIndex].Members.Add(newUser);
- }
- teamRegistration = Console.ReadLine();
- }
- var teamsToDisband = teams.OrderBy(x => x.TeamName).Where(x => x.Members.Count == 0);
- var fullTeams = teams.
- OrderByDescending(x => x.Members.Count).
- ThenBy(x => x.TeamName).
- Where(x => x.Members.Count > 0);
- foreach (var team in fullTeams)
- {
- Console.WriteLine($"{team.TeamName}");
- Console.WriteLine($"- {team.CreatorName}");
- foreach (var member in team.Members.OrderBy(x => x))
- {
- Console.WriteLine($"-- {member}");
- }
- }
- Console.WriteLine("Teams to disband:");
- foreach (var item in teamsToDisband)
- {
- Console.WriteLine(item.TeamName);
- }
- }
- }
- }
- //---------------------------------------6--------------------------------------------
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _06._Vehicle_Catalogue
- {
- public class Vehicle_Catalogue
- {
- public static void Main()
- {
- List<Vehicle> catalogue = new List<Vehicle>();
- while (true)
- {
- string[] inputTokens = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
- if (inputTokens[0] == "End")
- {
- break;
- }
- string type = inputTokens[0].ToLower();
- string model = inputTokens[1];
- string color = inputTokens[2].ToLower();
- int horsePower = int.Parse(inputTokens[3]);
- var currentVehicle = new Vehicle(type, model, color, horsePower);
- catalogue.Add(currentVehicle);
- }
- while (true)
- {
- string model = Console.ReadLine();
- if (model == "Close the Catalogue")
- {
- break;
- }
- Console.WriteLine(catalogue.Find(x => x.Model == model));
- }
- var onlyCars = catalogue.Where(x => x.Type == "car").ToList();
- var onlyTrucks = catalogue.Where(x => x.Type == "truck").ToList();
- double totalCarsHorsepower = 0;
- double totalTrucksHorsepower = 0;
- foreach (var car in onlyCars)
- {
- totalCarsHorsepower += car.HorsePower;
- }
- foreach (var truck in onlyTrucks)
- {
- totalTrucksHorsepower += truck.HorsePower;
- }
- double averageCarsHorsepower = totalCarsHorsepower / onlyCars.Count;
- double averageTrucksHorsepower = totalTrucksHorsepower / onlyTrucks.Count;
- if (onlyCars.Count > 0)
- {
- Console.WriteLine($"Cars have average horsepower of: {averageCarsHorsepower:f2}.");
- }
- else
- {
- Console.WriteLine($"Cars have average horsepower of: {0:f2}.");
- }
- if (onlyTrucks.Count > 0)
- {
- Console.WriteLine($"Trucks have average horsepower of: {averageTrucksHorsepower:f2}.");
- }
- else
- {
- Console.WriteLine($"Trucks have average horsepower of: {0:f2}.");
- }
- }
- }
- public class Vehicle
- {
- public Vehicle(string type, string model, string color, int horsePower)
- {
- this.Type = type;
- this.Model = model;
- this.Color = color;
- this.HorsePower = horsePower;
- }
- public string Type { get; set; }
- public string Model { get; set; }
- public string Color { get; set; }
- public int HorsePower { get; set; }
- public override string ToString()
- {
- string vehicleStr = $"Type: {(this.Type == "car" ? "Car" : "Truck")}{Environment.NewLine}" +
- $"Model: {this.Model}{Environment.NewLine}" +
- $"Color: {this.Color}{Environment.NewLine}" +
- $"Horsepower: {this.HorsePower}";
- return vehicleStr;
- }
- }
- }
- //--------------------------------------------7--------------------------------------------------
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Order_by_Age
- {
- class Person
- {
- public string Name { get; set; }
- public int ID { get; set; }
- public int Age { get; set; }
- }
- class Program
- {
- public static void Main(string[] args)
- {
- List<string> tokens = Console.ReadLine().Split().ToList();
- List<Person> list = new List<Person>();
- while (tokens[0] != "End")
- {
- string name = tokens[0];
- int id = int.Parse(tokens[1]);
- int age = int.Parse(tokens[2]);
- Person person = new Person()
- {
- Name = name,
- ID = id,
- Age = age
- };
- list.Add(person);
- tokens = Console.ReadLine().Split().ToList();
- }
- var result = list.OrderBy(person => person.Age);
- foreach (var item in result)
- {
- Console.WriteLine($"{item.Name} with ID: {item.ID} is {item.Age} years old.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement