Compare length of two strings: Difference between revisions
Content added Content deleted
Line 187: | Line 187: | ||
{ |
{ |
||
char Q = '"'; |
char Q = '"'; |
||
string |
string hasLength = " has length "; |
||
string |
string predicateMax = " and is the longest string"; |
||
string |
string predicateMin = " and is the shortest string"; |
||
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 |
int maxLength = li[0].Item1; |
||
int |
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 == |
if (length == maxLength) |
||
predicate = |
predicate = predicateMax; |
||
else if (length == |
else if (length == minLength) |
||
predicate = |
predicate = predicateMin; |
||
else |
else |
||
predicate = |
predicate = predicateAve; |
||
Console.WriteLine(Q + str + Q + |
Console.WriteLine(Q + str + Q + hasLength + length + predicate); |
||
} |
} |
||
} |
} |