**Description:**

An *alphanumeric* ordering of strings is defined as follows: each string is considered as a sequence of tokens, where each token is a letter or a number (as opposed to an isolated digit, as is the case of lexicographic ordering). For example, the tokens of a string `"ab01c004"`

are `[a, b, 01, c, 004]`

. In order to compare two strings, you break them down into tokens and compare corresponding pairs of tokens with each other (i.e. first token of the first string, with the first token of the second string etc).

Here is how tokens are compared:

- If a letter is compared with another letter, the usual order applies.
- A number is always
*less* than a letter.
- When two numbers are compared, their values are compared. Leading zeros, if any, are ignored.

If at some point one string has no more tokens left while the other one still does, the one with fewer tokens is considered *smaller*.

If the two strings `s1`

and `s2`

appear to be equal, consider the smallest index `i`

such that `tokens(s1)[i]`

and `tokens(s2)[i]`

(where `tokes(s)[i]`

is the `i`^{th}

token of string `s`

) differ only by the number of leading zeros. If no such `i`

exists, the strings are indeed equal. Otherwise, the string whose `i`^{th}

token has more leading zeros is considered less.

Here are some examples of comparing strings using alphanumeric ordering.

```
"a" < "a1" < "ab"
"ab42" < "ab000144" < "ab00144" < "ab144" < "ab000144x"
"x11y012" < "x011y13"
```

**Example**

- For
`s1 = "a"`

and `s2 = "a1"`

, the output should be

`alphanumericLess(s1, s2) = true`

;
- For
`s1 = "ab"`

and `s2 = "a1"`

, the output should be

`alphanumericLess(s1, s2) = false`

.

**Input/Output**

**Tests:**

**Solution:**

bool alphanumericLess(string s1, string s2) {
string[] l1 = getTokens(s1);
string[] l2 = getTokens(s2);
for(int i=0;i<Math.Max(l1.Length,l2.Length);i++) {
if(i==l1.Length)
return true;
if(i==l2.Length)
return false;
if(!isDigit(l1[i]) && !isDigit(l2[i])) {
if(string.Compare(l1[i],l2[i],false)<0)
return true;
else if(string.Compare(l1[i],l2[i],false)>0)
return false;
}
else if(isDigit(l1[i])||isDigit(l2[i])) {
if(isDigit(l1[i])&&isDigit(l2[i])) {
if(int.Parse(l1[i])==int.Parse(l2[i]))
return l1[i].Length>l2[i].Length;
else
return int.Parse(l1[i])<int.Parse(l2[i]);
}
else if(isDigit(l1[i]))
return true;
else
return false;
}
}
return false;
}
string[] getTokens(string s) {
List<string> result = new List<string>();
bool isDigit = false;
char currentC;
string strItem="";
for(int index=0;index<s.Length;index++) {
currentC = s[index];
if(48<=currentC && currentC <=57) {
if(isDigit)
strItem+=currentC;
else {
strItem=""+currentC;
}
isDigit= true;
}
else {
result.Add(""+currentC);
strItem="";
isDigit = false;
}
}
if(isDigit && !string.IsNullOrEmpty(strItem))
result.Add(strItem);
return result.ToArray();
}
bool isDigit(string s) {
int test;
return int.TryParse(s, out test);
}