roman.potapkin
BAN USERThere is error because if we compare "4.2" and "3.1.1" then we get 42 and 311 as integers, so 311 will be greater that 42 as integer, but 4.2 as version is latest.
 roman.potapkin January 21, 2014Who are saying that EACH cell in this matrix is translated to memory or any storage? We can save only notnull values into memory and realise function which return value (or null) by index. For example, excel do not save empty cells in a memory. Moreover, this task is abstract and we must solve it without any connections to memory size and real times.
 roman.potapkin November 06, 2013Each thread have to calculate a part of array. Size of part X is M/N, and last part size is MX*(N1); each thread add numbers to a local variable and add this value to global variable via atomic operation.
 roman.potapkin October 04, 2013This solution is not correct because if you compare 100 and 2 as strings you will see that 2 is less than 100.
 roman.potapkin October 04, 2013Which will be result of comparing "1.2.0" and "1.10.0"?
 roman.potapkin October 03, 2013There must be 2 counters (result counter and temporary counter);
1) Read chars one by one; if char is dot, then just increment temporary counter; else (in case of end of file also) if result counter is less than temporary counter then set result counter to temporary; reset temporary counter. At the finish in the temporary counter will be max value of consecutive chars.
There is a solution. A method returns 0 if the versuions are equal, 1 if first version less then second, and 1 in case of first version above than second. First of all, I splited strings by parts and then walk on the parts with converting to int. Also, in case of comparing "1.0" and "1" the method returns equal.
public int Compare(string version1, string version2)
{
var versionParts1 = version1.Split('.');
var versionParts2 = version2.Split('.');
var maxLength = Math.Max(versionParts1.Length, versionParts2.Length);
for (var n = 0; n < maxLength; n++)
{
int part1 = 0, part2 = 0;
if (n < versionParts1.Length)
part1 = int.Parse(versionParts1[n]);
if (n < versionParts2.Length)
part2 = int.Parse(versionParts2[n]);
if (part1 < part2)
return 1;
if (part2 < part1)
return 1;
}
return 0;
}

roman.potapkin
October 03, 2013 Open Chat in New Window
switch is condition operator
 roman.potapkin February 25, 2014