-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMergeEqualsCodeforces.cs
More file actions
109 lines (81 loc) · 2.93 KB
/
MergeEqualsCodeforces.cs
File metadata and controls
109 lines (81 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//using System;
//using System.Collections.Generic;
//namespace CodeForecs
//{
// public class DictionaryKey
// {
// public long Number { get; set; }
// public int Index { get; set; }
// public DictionaryKey(long number, int index)
// {
// Number = number;
// Index = index;
// }
// }
// public class DictionaryKeyEqualityComparer : IEqualityComparer<DictionaryKey>
// {
// public bool Equals(DictionaryKey x, DictionaryKey y)
// {
// if (x == null || y == null)
// return false;
// if(x.Number == y.Number)
// {
// y.Index = x.Index;
// return true;
// }
// return false;
// }
// public int GetHashCode(DictionaryKey obj)
// {
// return obj.Number.GetHashCode();
// }
// }
// public class DictionaryKeyComparer : Comparer<DictionaryKey>
// {
// public override int Compare(DictionaryKey x, DictionaryKey y)
// {
// return x.Index.CompareTo(y.Index);
// }
// }
// class MergeEqualsCodeforces
// {
// public static void Main(string[] args)
// {
// int size = Convert.ToInt32(Console.ReadLine());
// var inputArray = Console.ReadLine().Split(' ');
// long[] array = new long[size];
// DictionaryKeyEqualityComparer dictionaryKeyEqualityComparer = new DictionaryKeyEqualityComparer();
// IDictionary<DictionaryKey, int> dict = new Dictionary<DictionaryKey, int>(dictionaryKeyEqualityComparer);
// for(int i = 0; i < size; i++)
// {
// array[i] = Convert.ToInt64(inputArray[i]);
// DictionaryKey obj = new DictionaryKey(array[i], i);
// Process(obj, i, array, dict);
// }
// DictionaryKeyComparer dictionaryKeyComparer = new DictionaryKeyComparer();
// dict = new SortedDictionary<DictionaryKey, int>(dict, dictionaryKeyComparer);
// Console.WriteLine(dict.Count);
// foreach (KeyValuePair<DictionaryKey, int> keyValuePair in dict)
// {
// Console.Write(keyValuePair.Key.Number + " ");
// }
// //Console.ReadKey();
// }
// private static void Process(DictionaryKey obj, int index, long[] array, IDictionary<DictionaryKey, int> dict)
// {
// if(dict.ContainsKey(obj))
// {
// int oldIndex = obj.Index;
// array[index] += array[oldIndex];
// array[oldIndex] = -1;
// dict.Remove(obj);
// DictionaryKey obj1 = new DictionaryKey(array[index], index);
// Process(obj1, index, array, dict);
// }
// else
// {
// dict.Add(obj, index);
// }
// }
// }
//}