ДГП Десять

All generations.

generate functionFri, 20 Jan 2023

You are given a set of time intervals. Each segment is set in the format HH:MM:SS-HH:MM:SS, that is, first the hours, minutes and seconds of the left border of the segment are set, and then the hours, minutes and seconds of the right border. You need to validate a given set of time intervals. In other words, you need to check the following conditions: the hours, minutes and seconds are set correctly (that is, the hours are in the range from 0 to 23, and the minutes and seconds are in the range from 0 to 59); the left boundary of the segment is no later than its right boundary (but the boundaries may be equal); no pair of segments intersect (even at boundary points in time). You need to output YES if a given set of time intervals passes validation, and NO otherwise.

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { Console.WriteLine(ValidateTimeIntervals(new string[] { "23:59:59-23:59:59", "23:59:59-23:59:59" })); } static string ValidateTimeIntervals(string[] timeIntervals) { int[,] ranges = new int[timeIntervals.Length, 2]; for (int i = 0; i < timeIntervals.Length; i++) { string[] splitStr = timeIntervals[i].Split('-'); ranges[i, 0] = TimeToInt(splitStr[0]); ranges[i, 1] = TimeToInt(splitStr[1]); } for (int i = 0; i < timeIntervals.Length; i++)

testsFri, 20 Jan 2023

using System; using System.Collections.Generic; using System.Linq; using static System.Net.Mime.MediaTypeNames; public class Program { public static void Main(string[] args) { var testCaseCount = int.Parse(Console.ReadLine()); List<RangeDate> rd; List<string> results = new List<string>(); for (var i = 0; i < testCaseCount; i++) { rd = new List<RangeDate>(); var countT = int.Parse(Console.ReadLine()); string result = "YES"; for (int j = 0; j < countT; j++) { if (!result.StartsWith("NO")) { try { var NandM = Console.ReadLine().Split('-').Select(it => DateTime.Parse(it)).ToArray(); var myRange = new RangeDate(NandM[0], NandM[1]); if (!myRange.rangeCorrect()) result = "NO"; //if (rd.Count < 50) //{ // var test = rd.Select(s => s.IntersectsWith(myRange)).ToList(); // if (test.Exists(t => t == true)) result = "NO"; //} //totals += (int)myRange.GetInterval().TotalSeconds; if (rd.Contains(myRange)) result = "NO"; rd.Add(myRange); } catch (Exception) { result = "NO"; } } else { var NandM = Console.ReadLine(); } } //results.Add(result); Console.WriteLine(result); } //foreach (var item in results) //{ // Console.WriteLine(item); //} } } public class RangeDate { DateTime TimeStart; DateTime TimeEnd; public RangeDate(DateTime ds, DateTime de) { this.TimeStart = ds; this.TimeEnd = de; } public bool rangeCorrect() { return this.TimeStart <= this.TimeEnd; } public bool IntersectsWith(RangeDate otherPeriod) { return !(this.TimeStart > otherPeriod.TimeEnd || this.TimeEnd < otherPeriod.TimeStart); } public TimeSpan GetInterval() { return this.TimeEnd - this.TimeStart; } public override bool Equals(Object obj) { //Check for null and compare run-time types. if ((obj == null) || !this.GetType().Equals(obj.GetType())) { return false; } else { RangeDate p = (RangeDate)obj; return !(this.TimeStart > p.TimeEnd || this.TimeEnd < p.TimeStart); } } }

generate functionTue, 07 Feb 2023

wpf listcollectionview grouping by multiple columns and calculating the amount and quantity

public void group_multi_column_and_calculate_amount_and_quantity() { var c = new ListCollectionView(Items) { GroupDescriptions = { new PropertyGroupDescription("Name"), new PropertyGroupDescription("Date") } }; c.GroupDescriptions.Add(new PropertyGroupDescription("Name")); c.GroupDescriptions.Add(new PropertyGroupDescription("Date")); c.GroupDescriptions.Add(new PropertyGroupDescription("Product")); c.GroupDescriptions.Add(new PropertyGroupDescription("Quantity")); c.GroupDescriptions.Add(new PropertyGroupDescription("Amount")); dataGrid.ItemsSource = c; }

generate functionTue, 07 Feb 2023

order selection function with grouping by month

public IEnumerable<Order> GetOrdersByMonth(int year) { var orders = from order in _orders where order.OrderedDate.Year == year group order by order.OrderedDate.Month into g orderby g.Key select g; foreach (var group in orders) { Console.WriteLine($"Month: {group.Key}"); foreach (var order in group) { Console.WriteLine($"\t{order}"); } } }

generate functionFri, 20 Jan 2023

You are given a set of time intervals. Each segment is set in the format HH:MM:SS-HH:MM:SS, that is, first the hours, minutes and seconds of the left border of the segment are set, and then the hours, minutes and seconds of the right border. You need to validate a given set of time intervals. In other words, you need to check the following conditions: the hours, minutes and seconds are set correctly (that is, the hours are in the range from 0 to 23, and the minutes and seconds are in the range from 0 to 59); the left boundary of the segment is no later than its right boundary (but the boundaries may be equal); no pair of segments intersect (even at boundary points in time). You need to output YES if a given set of time intervals passes validation, and NO otherwise.

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Globalization; using System.Collections; using System.IO; class Solution { static void Main(String[] args) { int N = int.Parse(Console.ReadLine()); var times = new ArrayList(); var intervals = new ArrayList(); int i = 0; while(i < N){ var time = Console.ReadLine(); if(!times.Contains(time)){ times.Add(time); } i++; } foreach(var time in times){ var interval = time.Split('-'); var left = interval[0]; var right = interval[1]; intervals.Add(new Interval(left, right)); } bool valid = true; for(int j = 0; j <

generate functionTue, 07 Feb 2023

wpf listcollectionview grouping by multiple columns

public class MyClass { public string ItemName { get; set; } public string ItemType { get; set; } public string ItemGroup { get; set; } } var myView = new CollectionViewSource {Source = myCollection}.View; myView.GroupDescriptions.Add(new PropertyGroupDescription("ItemGroup")); myView.SortDescriptions.Add(new SortDescription("ItemType", ListSortDirection.Ascending)); myView.SortDescriptions.Add(new SortDescription("ItemName", ListSortDirection.Ascending));

generate functionTue, 07 Feb 2023

wpf listcollectionview grouping by multiple columns

// reference: http://stackoverflow.com/a/13017748/1768303 // model public class Person { public string FirstName { get; set; } public string LastName { get; set; } public string City { get; set; } } // ViewModel List<Person> people = new List<Person> { new Person { FirstName = "John", LastName = "Doe", City = "London"}, new Person { FirstName = "John", LastName = "Smith", City = "New York" }, new Person { FirstName = "Jane", LastName = "Smith", City = "London" }, new Person { FirstName = "John", LastName = "Smith", City = "Paris" }, }; ListCollectionView view = new ListCollectionView(people); view.GroupDescriptions.Add(new PropertyGroupDescription("FirstName")); view.GroupDescriptions.Add(new PropertyGroupDescription("LastName")); // View <ListBox x:Name="my

generate functionTue, 07 Feb 2023

wpf listcollectionview grouping by multiple columns

public void GroupByMulti(ListCollectionView _list, string[] _properties) { var groupProperty = _list.GroupDescriptions.FirstOrDefault(); if (groupProperty == null) { foreach (string _property in _properties) { _list.GroupDescriptions.Add(new PropertyGroupDescription(_property)); } } else { for (int i = 1; i < _properties.Length; i++) { _list.GroupDescriptions.Add(new PropertyGroupDescription(_properties[i])); } } }

testsFri, 20 Jan 2023

using System; using System.Collections.Generic; using System.Linq; using static System.Net.Mime.MediaTypeNames; public class Program { public static void Main(string[] args) { var testCaseCount = int.Parse(Console.ReadLine()); List<RangeDate> rd; List<string> results = new List<string>(); for (var i = 0; i < testCaseCount; i++) { rd = new List<RangeDate>(); var countT = int.Parse(Console.ReadLine()); string result = "YES"; for (int j = 0; j < countT; j++) { if (!result.StartsWith("NO")) { try { var NandM = Console.ReadLine().Split('-').Select(it => DateTime.Parse(it)).ToArray(); var myRange = new RangeDate(NandM[0], NandM[1]); if (!myRange.rangeCorrect()) result = "NO"; //if (rd.Count < 50) //{ // var test = rd.Select(s => s.IntersectsWith(myRange)).ToList(); // if (test.Exists(t => t == true)) result = "NO"; //} //totals += (int)myRange.GetInterval().TotalSeconds; if (rd.Contains(myRange)) result = "NO"; rd.Add(myRange); } catch (Exception) { result = "NO"; } } else { var NandM = Console.ReadLine(); } } //results.Add(result); Console.WriteLine(result); } //foreach (var item in results) //{ // Console.WriteLine(item); //} } } public class RangeDate { DateTime TimeStart; DateTime TimeEnd; public RangeDate(DateTime ds, DateTime de) { this.TimeStart = ds; this.TimeEnd = de; } public bool rangeCorrect() { return this.TimeStart <= this.TimeEnd; } public bool IntersectsWith(RangeDate otherPeriod) { return !(this.TimeStart > otherPeriod.TimeEnd || this.TimeEnd < otherPeriod.TimeStart); } public TimeSpan GetInterval() { return this.TimeEnd - this.TimeStart; } public override bool Equals(Object obj) { //Check for null and compare run-time types. if ((obj == null) || !this.GetType().Equals(obj.GetType())) { return false; } else { RangeDate p = (RangeDate)obj; return !(this.TimeStart > p.TimeEnd || this.TimeEnd < p.TimeStart); } } }

generate functionTue, 07 Feb 2023

listcollectionview groupingcolumns and calculating the amount and quantity

private void ListCollectionView_GroupingColumnsChanged(object sender, NotifyCollectionChangedEventArgs e) { if (ListCollectionView.IsGrouping == true) { if (ListCollectionView.Groups.Count > 0) { int count = 0; int quantity = 0; for (int i = 0; i < ListCollectionView.Groups.Count; i++) { foreach (InventoryItem item in ListCollectionView.Groups[i].Items) { count++; quantity += item.Quantity; } } _groupQuantity = quantity; _groupCount = count; OnPropertyChanged("GroupQuantity"); OnPropertyChanged("GroupCount"); } else { _groupCount = 0; _groupQuantity = 0; OnPropertyChanged("GroupQuantity"); OnPropertyChanged("GroupCount"); } } }

class from descriptionFri, 20 Jan 2023

In many social networks, users have the option to specify other users as their friends. In addition, there is often a friend recommendation system that shows users people they know indirectly (through one of their friends) and suggests adding these people to the friends list. You have to develop a system for recommending friends. There are n users in the social network we are interested in, each of which is assigned a unique id from 1 to n. Each user of this network has no more than 5 friends. Obviously, no user is a friend to himself, and if user x is in user y's friends list, then user y is also in user x's friends list. Let's describe how the list of possible friends for each user should be formed. For user x, the list should include users y such that: y is not a friend of x and is not the same as x; user y and user x have at least one mutual friend; there is no such user y' who satisfies the first two constraints, and who has strictly more mutual friends with x than y has with x. In other words, the list of possible friends of user x includes all such users who are not his friends, for whom the number of mutual friends with x is maximum. Note that the list of possible friends may be empty. You have to write a program that generates lists of possible friends for all users of the network according to a given structure of the social network.

class FriendRecommender: def recommend(self, n, friends): """ :param n: the number of users in the network :type n: int :param friends: two-dimensional list of integers representing the structure of the network :type friends: list[list[int]] :return: list of possible friends for each user :rtype: list[set[int]] """

Python
View
generate functionFri, 20 Jan 2023

You are given a set of time intervals. Each segment is set in the format HH:MM:SS-HH:MM:SS, that is, first the hours, minutes and seconds of the left border of the segment are set, and then the hours, minutes and seconds of the right border. You need to validate a given set of time intervals. In other words, you need to check the following conditions: the hours, minutes and seconds are set correctly (that is, the hours are in the range from 0 to 23, and the minutes and seconds are in the range from 0 to 59); the left boundary of the segment is no later than its right boundary (but the boundaries may be equal); no pair of segments intersect (even at boundary points in time). You need to output YES if a given set of time intervals passes validation, and NO otherwise.

using System; using System.Collections.Generic; using System.Linq; namespace Test { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] param = Console.ReadLine().Trim().Split(new[] { ' ' }); var input = new List<string[]>(); for (int j = 0; j < param.Length; j++) { input.Add(param[j].Split(new[] { ':' })); } int hour1 = int.Parse(input[0][0]); int min1 = int.Parse(input[0][1]); int second1 = int.Parse(input[0][2]); int hour2 = int.Parse(input[1][0]); int min2 = int.Parse(input[1][1]); int second2 = int.

generate functionTue, 07 Feb 2023

wpf listcollectionview grouping by multiple columns. Only view

private void GroupingByMultipleColumns(ObservableCollection<DummyModel> p_list) { var _listcollectionview = new ListCollectionView(p_list); _listcollectionview.GroupDescriptions.Add(new PropertyGroupDescription("Name")); _listcollectionview.GroupDescriptions.Add(new PropertyGroupDescription("Age")); Datagrid1.ItemsSource = _listcollectionview; }

testsFri, 20 Jan 2023

using System; using System.Collections.Generic; using System.Linq; using static System.Net.Mime.MediaTypeNames; public class Program { public static void Main(string[] args) { var testCaseCount = int.Parse(Console.ReadLine()); List<RangeDate> rd; List<string> results = new List<string>(); for (var i = 0; i < testCaseCount; i++) { rd = new List<RangeDate>(); var countT = int.Parse(Console.ReadLine()); string result = "YES"; for (int j = 0; j < countT; j++) { if (!result.StartsWith("NO")) { try { var NandM = Console.ReadLine().Split('-').Select(it => DateTime.Parse(it)).ToArray(); var myRange = new RangeDate(NandM[0], NandM[1]); if (!myRange.rangeCorrect()) result = "NO"; //if (rd.Count < 50) //{ // var test = rd.Select(s => s.IntersectsWith(myRange)).ToList(); // if (test.Exists(t => t == true)) result = "NO"; //} //totals += (int)myRange.GetInterval().TotalSeconds; if (rd.Contains(myRange)) result = "NO"; rd.Add(myRange); } catch (Exception) { result = "NO"; } } else { var NandM = Console.ReadLine(); } } //results.Add(result); Console.WriteLine(result); } //foreach (var item in results) //{ // Console.WriteLine(item); //} } } public class RangeDate { DateTime TimeStart; DateTime TimeEnd; public RangeDate(DateTime ds, DateTime de) { this.TimeStart = ds; this.TimeEnd = de; } public bool rangeCorrect() { return this.TimeStart <= this.TimeEnd; } public bool IntersectsWith(RangeDate otherPeriod) { return !(this.TimeStart > otherPeriod.TimeEnd || this.TimeEnd < otherPeriod.TimeStart); } public TimeSpan GetInterval() { return this.TimeEnd - this.TimeStart; } public override bool Equals(Object obj) { //Check for null and compare run-time types. if ((obj == null) || !this.GetType().Equals(obj.GetType())) { return false; } else { RangeDate p = (RangeDate)obj; return !(this.TimeStart > p.TimeEnd || this.TimeEnd < p.TimeStart); } } }

## Author * **Thomas Finsterwald** - *Initial work* - [ThomasFinsterwald](https://github.com/ThomasFinsterwald) ## Acknowledgments * **HackerRank** - *Initial work* - [Hackerrank](https://www.hackerrank.com/)

generate functionTue, 07 Feb 2023

wpf listcollectionview grouping by multiple columns

public class GroupData { public string Column1 { get; set; } public string Column2 { get; set; } } List<GroupData> data = new List<GroupData> (); ListCollectionView view = new ListCollectionView (data); view.GroupDescriptions.Add (new PropertyGroupDescription ("Column1")); view.GroupDescriptions.Add (new PropertyGroupDescription ("Column2"));

testsFri, 20 Jan 2023

using System; using System.Collections.Generic; using System.Linq; using static System.Net.Mime.MediaTypeNames; public class Program { public static void Main(string[] args) { var testCaseCount = int.Parse(Console.ReadLine()); List<RangeDate> rd; List<string> results = new List<string>(); for (var i = 0; i < testCaseCount; i++) { rd = new List<RangeDate>(); var countT = int.Parse(Console.ReadLine()); string result = "YES"; for (int j = 0; j < countT; j++) { if (!result.StartsWith("NO")) { try { var NandM = Console.ReadLine().Split('-').Select(it => DateTime.Parse(it)).ToArray(); var myRange = new RangeDate(NandM[0], NandM[1]); if (!myRange.rangeCorrect()) result = "NO"; //if (rd.Count < 50) //{ // var test = rd.Select(s => s.IntersectsWith(myRange)).ToList(); // if (test.Exists(t => t == true)) result = "NO"; //} //totals += (int)myRange.GetInterval().TotalSeconds; if (rd.Contains(myRange)) result = "NO"; rd.Add(myRange); } catch (Exception) { result = "NO"; } } else { var NandM = Console.ReadLine(); } } //results.Add(result); Console.WriteLine(result); } //foreach (var item in results) //{ // Console.WriteLine(item); //} } } public class RangeDate { DateTime TimeStart; DateTime TimeEnd; public RangeDate(DateTime ds, DateTime de) { this.TimeStart = ds; this.TimeEnd = de; } public bool rangeCorrect() { return this.TimeStart <= this.TimeEnd; } public bool IntersectsWith(RangeDate otherPeriod) { return !(this.TimeStart > otherPeriod.TimeEnd || this.TimeEnd < otherPeriod.TimeStart); } public TimeSpan GetInterval() { return this.TimeEnd - this.TimeStart; } public override bool Equals(Object obj) { //Check for null and compare run-time types. if ((obj == null) || !this.GetType().Equals(obj.GetType())) { return false; } else { RangeDate p = (RangeDate)obj; return !(this.TimeStart > p.TimeEnd || this.TimeEnd < p.TimeStart); } } }

generate functionTue, 07 Feb 2023

You are given a set of time intervals. Each segment is set in the format HH:MM:SS-HH:MM:SS, that is, first the hours, minutes and seconds of the left border of the segment are set, and then the hours, minutes and seconds of the right border. You need to validate a given set of time intervals. In other words, you need to check the following conditions: the hours, minutes and seconds are set correctly (that is, the hours are in the range from 0 to 23, and the minutes and seconds are in the range from 0 to 59); the left boundary of the segment is no later than its right boundary (but the boundaries may be equal); no pair of segments intersect (even at boundary points in time). You need to output YES if a given set of time intervals passes validation, and NO otherwise.

using System; using System.Collections.Generic; using System.IO; class Solution { static void Main() { var testCases = int.Parse(Console.ReadLine()); for(var i = 0; i < testCases; i++) { var times = new List<TimeSpan>(); var timesCount = int.Parse(Console.ReadLine()); for(var j = 0; j < timesCount; j++) { var timeString = Console.ReadLine(); var timeSplit = timeString.Split('-'); var leftTime = timeSplit[0]; var rightTime = timeSplit[1]; var leftTimeSpan = TimeSpan.Parse(leftTime); var rightTimeSpan = TimeSpan.Parse(rightTime); if(leftTimeSpan > rightTimeSpan) { Console.WriteLine("NO"); break; } if(

generate functionTue, 07 Feb 2023

wpf binding datetime , StringFormat=d

public class FormatConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { DateTime date = (DateTime)value; return date.Date.ToString("d"); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } }

class from descriptionFri, 20 Jan 2023

In many social networks, users have the option to specify other users as their friends. In addition, there is often a friend recommendation system that shows users people they know indirectly (through one of their friends) and suggests adding these people to the friends list. You have to develop a system for recommending friends. There are n users in the social network we are interested in, each of which is assigned a unique id from 1 to n. Each user of this network has no more than 5 friends. Obviously, no user is a friend to himself, and if user x is in user y's friends list, then user y is also in user x's friends list. Let's describe how the list of possible friends for each user should be formed. For user x, the list should include users y such that: y is not a friend of x and is not the same as x; user y and user x have at least one mutual friend; there is no such user y' who satisfies the first two constraints, and who has strictly more mutual friends with x than y has with x. In other words, the list of possible friends of user x includes all such users who are not his friends, for whom the number of mutual friends with x is maximum. Note that the list of possible friends may be empty. You have to write a program that generates lists of possible friends for all users of the network according to a given structure of the social network.

using System; using System.Collections.Generic; namespace Friends { public class Friends { public static void Main() { int n = int.Parse(Console.ReadLine()); var network = new List<List<int>>(); for (int i = 0; i < n; i++) { var line = Console.ReadLine().Trim(); if (line.Length == 0) network.Add(new List<int>()); else network.Add(new List<int>(Array.ConvertAll(line.Split(' '), int.Parse))); } var possibleFriends = new List<List<int>>(); for (int i = 0; i < n; i++) { possibleFriends.Add(new List<int>()); for (int j = 0; j < n; j++) { if (i == j || network[i].Contains(j)) continue; int mutualFriends = 0; fore

generate functionTue, 07 Feb 2023

wpf binding datetime , StringFormat=d

public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var date = (DateTime)value; if (date == DateTime.MinValue) return ""; return date.ToString("d", CultureInfo.CurrentCulture); }

testsFri, 20 Jan 2023

using System; using System.Collections.Generic; using System.Linq; using static System.Net.Mime.MediaTypeNames; public class Program { public static void Main(string[] args) { var testCaseCount = int.Parse(Console.ReadLine()); List<RangeDate> rd; List<string> results = new List<string>(); for (var i = 0; i < testCaseCount; i++) { rd = new List<RangeDate>(); var countT = int.Parse(Console.ReadLine()); string result = "YES"; for (int j = 0; j < countT; j++) { if (!result.StartsWith("NO")) { try { var NandM = Console.ReadLine().Split('-').Select(it => DateTime.Parse(it)).ToArray(); var myRange = new RangeDate(NandM[0], NandM[1]); if (!myRange.rangeCorrect()) result = "NO"; //if (rd.Count < 50) //{ // var test = rd.Select(s => s.IntersectsWith(myRange)).ToList(); // if (test.Exists(t => t == true)) result = "NO"; //} //totals += (int)myRange.GetInterval().TotalSeconds; if (rd.Contains(myRange)) result = "NO"; rd.Add(myRange); } catch (Exception) { result = "NO"; } } else { var NandM = Console.ReadLine(); } } //results.Add(result); Console.WriteLine(result); } //foreach (var item in results) //{ // Console.WriteLine(item); //} } } public class RangeDate { DateTime TimeStart; DateTime TimeEnd; public RangeDate(DateTime ds, DateTime de) { this.TimeStart = ds; this.TimeEnd = de; } public bool rangeCorrect() { return this.TimeStart <= this.TimeEnd; } public bool IntersectsWith(RangeDate otherPeriod) { return !(this.TimeStart > otherPeriod.TimeEnd || this.TimeEnd < otherPeriod.TimeStart); } public TimeSpan GetInterval() { return this.TimeEnd - this.TimeStart; } public override bool Equals(Object obj) { //Check for null and compare run-time types. if ((obj == null) || !this.GetType().Equals(obj.GetType())) { return false; } else { RangeDate p = (RangeDate)obj; return !(this.TimeStart > p.TimeEnd || this.TimeEnd < p.TimeStart); } } }

generate functionTue, 07 Feb 2023

wpf listcollectionview grouping by multiple columns and calculating the amount and quantity

public class ProductSummary { public int ProductId { get; set; } public string ProductName { get; set; } public double Amount { get; set; } public double Quantity { get; set; } } private List<Product> products; public List<Product> Products { get { return products; } set { products = value; RaisePropertyChanged("Products"); } } public ListCollectionView ProductsCollectionView { get; set; } private void Grouping() { ProductsCollectionView = new ListCollectionView(Products); ProductsCollectionView.GroupDescriptions.Add(new PropertyGroupDescription("CategoryId")); ProductsCollectionView.GroupDescriptions.Add(new PropertyGroupDescription("TypeId")); ProductsCollectionView.GroupDescriptions.Add(new PropertyGroupDescription("VendorId")); ProductsCollectionView.CustomSort = new ProductComparer(); ProductsCollectionView.GroupSummary.Add(new GroupSummary<Product, ProductSummary>() { PropertySelector = (x

testsFri, 20 Jan 2023

using System; using System.Collections.Generic; using System.Linq; using static System.Net.Mime.MediaTypeNames; public class Program { public static void Main(string[] args) { var testCaseCount = int.Parse(Console.ReadLine()); List<RangeDate> rd; List<string> results = new List<string>(); for (var i = 0; i < testCaseCount; i++) { rd = new List<RangeDate>(); var countT = int.Parse(Console.ReadLine()); string result = "YES"; for (int j = 0; j < countT; j++) { if (!result.StartsWith("NO")) { try { var NandM = Console.ReadLine().Split('-').Select(it => DateTime.Parse(it)).ToArray(); var myRange = new RangeDate(NandM[0], NandM[1]); if (!myRange.rangeCorrect()) result = "NO"; //if (rd.Count < 50) //{ // var test = rd.Select(s => s.IntersectsWith(myRange)).ToList(); // if (test.Exists(t => t == true)) result = "NO"; //} //totals += (int)myRange.GetInterval().TotalSeconds; if (rd.Contains(myRange)) result = "NO"; rd.Add(myRange); } catch (Exception) { result = "NO"; } } else { var NandM = Console.ReadLine(); } } //results.Add(result); Console.WriteLine(result); } //foreach (var item in results) //{ // Console.WriteLine(item); //} } } public class RangeDate { DateTime TimeStart; DateTime TimeEnd; public RangeDate(DateTime ds, DateTime de) { this.TimeStart = ds; this.TimeEnd = de; } public bool rangeCorrect() { return this.TimeStart <= this.TimeEnd; } public bool IntersectsWith(RangeDate otherPeriod) { return !(this.TimeStart > otherPeriod.TimeEnd || this.TimeEnd < otherPeriod.TimeStart); } public TimeSpan GetInterval() { return this.TimeEnd - this.TimeStart; } public override bool Equals(Object obj) { //Check for null and compare run-time types. if ((obj == null) || !this.GetType().Equals(obj.GetType())) { return false; } else { RangeDate p = (RangeDate)obj; return !(this.TimeStart > p.TimeEnd || this.TimeEnd < p.TimeStart); } } }

class from descriptionFri, 20 Jan 2023

In many social networks, users have the option to specify other users as their friends. In addition, there is often a friend recommendation system that shows users people they know indirectly (through one of their friends) and suggests adding these people to the friends list. You have to develop a system for recommending friends. There are n users in the social network we are interested in, each of which is assigned a unique id from 1 to n. Each user of this network has no more than 5 friends. Obviously, no user is a friend to himself, and if user x is in user y's friends list, then user y is also in user x's friends list. Let's describe how the list of possible friends for each user should be formed. For user x, the list should include users y such that: y is not a friend of x and is not the same as x; user y and user x have at least one mutual friend; there is no such user y' who satisfies the first two constraints, and who has strictly more mutual friends with x than y has with x. In other words, the list of possible friends of user x includes all such users who are not his friends, for whom the number of mutual friends with x is maximum. Note that the list of possible friends may be empty. You have to write a program that generates lists of possible friends for all users of the network according to a given structure of the social network.

#include <iostream> #include <vector> using namespace std; struct Relation { int user; int friend_; }; class Network { public: Network(int n) : nodes(n), friends(n) {} void Add(const Relation& r) { nodes[r.user - 1].emplace_back(r.friend_ - 1); nodes[r.friend_ - 1].emplace_back(r.user - 1); } vector<vector<int>> FindPotentialFriends() { for (int i = 0; i < nodes.size(); ++i) { for (auto fi : nodes[i]) { for (auto ffi : nodes[fi]) { if (i == ffi) continue; ++friends[i][ffi]; } } } vector<vector<int>> res; for (int i = 0; i < friends.size(); ++i) { vector<int> cur_friends

C++
View
generate functionFri, 20 Jan 2023

You are given a set of time intervals. Each segment is set in the format HH:MM:SS-HH:MM:SS, that is, first the hours, minutes and seconds of the left border of the segment are set, and then the hours, minutes and seconds of the right border. You need to validate a given set of time intervals. In other words, you need to check the following conditions: the hours, minutes and seconds are set correctly (that is, the hours are in the range from 0 to 23, and the minutes and seconds are in the range from 0 to 59); the left boundary of the segment is no later than its right boundary (but the boundaries may be equal); no pair of segments intersect (even at boundary points in time). You need to output YES if a given set of time intervals passes validation, and NO otherwise.

using System; using System.Globalization; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string[] time = Console.ReadLine().Split(' '); List<DateTime> start = new List<DateTime>(); List<DateTime> end = new List<DateTime>(); foreach (string s in time) { string[] times = s.Split('-'); string[] star = times[0].Split(':'); string[] endd = times[1].Split(':'); DateTime sta = new DateTime(2017, 1, 1, int.Parse(star[0]), int.Parse(star[1]), int.Parse(star[2])); DateTime en = new DateTime(2017, 1, 1, int.Parse(endd[0]), int.Parse(

class from descriptionFri, 20 Jan 2023

In many social networks, users have the option to specify other users as their friends. In addition, there is often a friend recommendation system that shows users people they know indirectly (through one of their friends) and suggests adding these people to the friends list. You have to develop a system for recommending friends. There are n users in the social network we are interested in, each of which is assigned a unique id from 1 to n. Each user of this network has no more than 5 friends. Obviously, no user is a friend to himself, and if user x is in user y's friends list, then user y is also in user x's friends list. Let's describe how the list of possible friends for each user should be formed. For user x, the list should include users y such that: y is not a friend of x and is not the same as x; user y and user x have at least one mutual friend; there is no such user y' who satisfies the first two constraints, and who has strictly more mutual friends with x than y has with x. In other words, the list of possible friends of user x includes all such users who are not his friends, for whom the number of mutual friends with x is maximum. Note that the list of possible friends may be empty. You have to write a program that generates lists of possible friends for all users of the network according to a given structure of the social network.

using System; using System.Collections.Generic; using System.Linq; namespace FriendsInNeed { class Program { private static int[][] graph; private static List<int>[] possibleFriends; private static HashSet<int>[] friends; private static int[] degrees; static void Main(string[] args) { ReadGraph(); possibleFriends = new List<int>[graph.Length]; friends = new HashSet<int>[graph.Length]; degrees = Enumerable.Repeat(0, graph.Length).ToArray(); CalculateDegrees(); CalculateFriends(); CalculatePossibleFriends(); PrintPossibleFriends(); } private static void CalculatePossibleFriends() { for (int i = 1; i < possibleFriends.Length; i++) { var possibleFriend = possibleFriends[i]; possibleFriend.Sort(); possibleFriends[i] = possibleFriend; } } private static void

generate functionTue, 07 Feb 2023

wpf listcollectionview grouping by multiple columns. Only view

public static void GroupBy(this ListCollectionView lcv, params string[] properties) { if (lcv == null) return; if (lcv.GroupDescriptions != null) lcv.GroupDescriptions.Clear(); if (properties != null && properties.Length > 0) { foreach (string p in properties) { PropertyGroupDescription groupDescription = new PropertyGroupDescription(p); lcv.GroupDescriptions.Add(groupDescription); } } else { lcv.IsLiveGrouping = false; } }

generate functionTue, 07 Feb 2023

listcollectionview groupingcolumns and calculating the amount and quantity

private void GetGroupedProducts(ObservableCollection<Product> products, ICollectionView view) { view.GroupDescriptions.Add(new PropertyGroupDescription("Category.Name")); var group = view.Groups[0]; MessageBox.Show( "The category is " + group.Name + " and there are " + group.ItemCount + " products in this category with a total value of " + group.Items.Cast<Product>().Sum(p => p.UnitPrice * p.UnitsInStock)); }

generate functionTue, 07 Feb 2023

wpf listcollectionview grouping by multiple columns and calculating the amount and quantity

ListCollectionView view = new ListCollectionView(lv.ItemsSource as IEnumerable); if (view.GroupDescriptions != null) { view.GroupDescriptions.Clear(); } else { view.GroupDescriptions = new ObservableCollection<GroupDescription>(); } view.GroupDescriptions.Add(new PropertyGroupDescription("Location")); view.GroupDescriptions.Add(new PropertyGroupDescription("Batch")); for (int i = 0; i < view.Groups.Count; i++) { Console.WriteLine("Amount: {0}", (view.Groups[i] as CollectionViewGroup).Items[0].GetType().GetProperty("Amount").GetValue((view.Groups[i] as CollectionViewGroup).Items[0])); Console.WriteLine("Quantity: {0}", (view.Groups[i] as CollectionViewGroup).Items[0].GetType().GetProperty("Quantity").GetValue((view.Groups[i] as CollectionViewGroup).Items[0]));

generate functionTue, 07 Feb 2023

wpf listcollectionview grouping by multiple columns and calculating the amount and quantity

var collection = new List<Result> { new Result {Name = "A", Security = "S1", Quantity = 5, Amount = 20}, new Result {Name = "A", Security = "S2", Quantity = 5, Amount = 20}, new Result {Name = "A", Security = "S3", Quantity = 5, Amount = 20}, new Result {Name = "B", Security = "S1", Quantity = 5, Amount = 20}, new Result {Name = "B", Security = "S2", Quantity = 5, Amount = 20}, new Result {Name = "C", Security = "S1", Quantity = 5, Amount = 20}, new Result {Name = "C", Security = "S2", Quantity = 5, Amount = 20}, new Result {Name = "C", Security = "S3", Quantity = 5, Amount = 20}, }; var cvs = new CollectionViewSource { Source = collection }; cvs.GroupDescriptions.Add(new PropertyGroupDescription("Name")); cvs.GroupDescriptions.Add

class from descriptionFri, 20 Jan 2023

In many social networks, users have the option to specify other users as their friends. In addition, there is often a friend recommendation system that shows users people they know indirectly (through one of their friends) and suggests adding these people to the friends list. You have to develop a system for recommending friends. There are n users in the social network we are interested in, each of which is assigned a unique id from 1 to n. Each user of this network has no more than 5 friends. Obviously, no user is a friend to himself, and if user x is in user y's friends list, then user y is also in user x's friends list. Let's describe how the list of possible friends for each user should be formed. For user x, the list should include users y such that: y is not a friend of x and is not the same as x; user y and user x have at least one mutual friend; there is no such user y' who satisfies the first two constraints, and who has strictly more mutual friends with x than y has with x. In other words, the list of possible friends of user x includes all such users who are not his friends, for whom the number of mutual friends with x is maximum. Note that the list of possible friends may be empty. You have to write a program that generates lists of possible friends for all users of the network according to a given structure of the social network.

using System; using System.Collections.Generic; using System.Linq; namespace Friends { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[,] matrix = new int[n, n]; for (int i = 0; i < n; i++) { int[] arr = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int j = 0; j < arr.Length; j++) { matrix[i, arr[j] - 1] = 1; matrix[arr[j] - 1, i] = 1; } } for (int i = 0; i < n; i++) { List<int> friends = new List<int>(); int mutualFriends = 0; for (int j = 0; j < n; j++) { if (matrix[i, j] == 0 && i

class from descriptionTue, 07 Feb 2023

the class of the work order with the fields number, month, technological operation, quantity, price, amount, worker calculate the number of technological operations per month for each worker

// Worker public class Worker { public int Number { get; set; } public string Name { get; set; } public string Profession { get; set; } public List<WorkOrder> WorkOrders { get; set; } public Worker() { WorkOrders = new List<WorkOrder>(); } public Worker(int number, string name, string profession) { Number = number; Name = name; Profession = profession; WorkOrders = new List<WorkOrder>(); } public void AddWorkOrder(WorkOrder workOrder) { WorkOrders.Add(workOrder); } public int GetNumberOfWorkOrdersByMonth(int month) { return WorkOrders.Count(wo => wo.Month == month); } }

generate functionTue, 07 Feb 2023

wpf listcollectionview grouping by multiple columns. Only view

public class ViewModel { private readonly ListCollectionView _collectionView; public ViewModel() { _collectionView = new ListCollectionView(myList); _collectionView.GroupDescriptions.Add(new PropertyGroupDescription("Name")); _collectionView.GroupDescriptions.Add(new PropertyGroupDescription("Age")); } public IEnumerable MyCollectionView { get { return _collectionView; } } }

generate functionTue, 07 Feb 2023

listcollectionview filtering current month

public class DateComparer : IComparer<DateTime> { public int Compare(DateTime x, DateTime y) { if (x.Year == y.Year && x.Month == y.Month) return 0; return 1; } } //... ListCollectionView lstCollView = new ListCollectionView(lst); lstCollView.Filter = (obj) => { DateTime dt = (DateTime)obj; if (dt.Year == DateTime.Now.Year && dt.Month == DateTime.Now.Month) return true; return false; };

testsFri, 20 Jan 2023

using System; using System.Collections.Generic; using System.Linq; using static System.Net.Mime.MediaTypeNames; public class Program { public static void Main(string[] args) { var testCaseCount = int.Parse(Console.ReadLine()); List<RangeDate> rd; List<string> results = new List<string>(); for (var i = 0; i < testCaseCount; i++) { rd = new List<RangeDate>(); var countT = int.Parse(Console.ReadLine()); string result = "YES"; for (int j = 0; j < countT; j++) { if (!result.StartsWith("NO")) { try { var NandM = Console.ReadLine().Split('-').Select(it => DateTime.Parse(it)).ToArray(); var myRange = new RangeDate(NandM[0], NandM[1]); if (!myRange.rangeCorrect()) result = "NO"; //if (rd.Count < 50) //{ // var test = rd.Select(s => s.IntersectsWith(myRange)).ToList(); // if (test.Exists(t => t == true)) result = "NO"; //} //totals += (int)myRange.GetInterval().TotalSeconds; if (rd.Contains(myRange)) result = "NO"; rd.Add(myRange); } catch (Exception) { result = "NO"; } } else { var NandM = Console.ReadLine(); } } //results.Add(result); Console.WriteLine(result); } //foreach (var item in results) //{ // Console.WriteLine(item); //} } } public class RangeDate { DateTime TimeStart; DateTime TimeEnd; public RangeDate(DateTime ds, DateTime de) { this.TimeStart = ds; this.TimeEnd = de; } public bool rangeCorrect() { return this.TimeStart <= this.TimeEnd; } public bool IntersectsWith(RangeDate otherPeriod) { return !(this.TimeStart > otherPeriod.TimeEnd || this.TimeEnd < otherPeriod.TimeStart); } public TimeSpan GetInterval() { return this.TimeEnd - this.TimeStart; } public override bool Equals(Object obj) { //Check for null and compare run-time types. if ((obj == null) || !this.GetType().Equals(obj.GetType())) { return false; } else { RangeDate p = (RangeDate)obj; return !(this.TimeStart > p.TimeEnd || this.TimeEnd < p.TimeStart); } } }

Questions about programming?Chat with your personal AI assistant