Compare length of two strings: Difference between revisions

Content added Content deleted
Line 187: Line 187:
{
{
char Q = '"';
char Q = '"';
string has_length = " has length ";
string hasLength = " has length ";
string predicate_max = " and is the longest string";
string predicateMax = " and is the longest string";
string predicate_min = " and is the shortest string";
string predicateMin = " and is the shortest string";
string predicate_ave = " and is neither the longest nor the shortest string";
string predicateAve = " and is neither the longest nor the shortest string";
string predicate;
string predicate;


Line 197: Line 197:
li[i] = (strings[i].Length, i);
li[i] = (strings[i].Length, i);
Array.Sort(li, ((int, int) a, (int, int) b) => b.Item1 - a.Item1);
Array.Sort(li, ((int, int) a, (int, int) b) => b.Item1 - a.Item1);
int max_length = li[0].Item1;
int maxLength = li[0].Item1;
int min_length = li[strings.Length - 1].Item1;
int minLength = li[strings.Length - 1].Item1;


for (int i = 0; i < strings.Length; i++)
for (int i = 0; i < strings.Length; i++)
Line 204: Line 204:
int length = li[i].Item1;
int length = li[i].Item1;
string str = strings[li[i].Item2];
string str = strings[li[i].Item2];
if (length == max_length)
if (length == maxLength)
predicate = predicate_max;
predicate = predicateMax;
else if (length == min_length)
else if (length == minLength)
predicate = predicate_min;
predicate = predicateMin;
else
else
predicate = predicate_ave;
predicate = predicateAve;
Console.WriteLine(Q + str + Q + has_length + length + predicate);
Console.WriteLine(Q + str + Q + hasLength + length + predicate);
}
}
}
}