-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtensionMethods.cs
52 lines (49 loc) · 1.1 KB
/
ExtensionMethods.cs
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
namespace ExtensionMethods
{
public static class MyExtension
{
public static List<string> ParseName(string s)
{
string[] lst = s.Split(new char[]{'.', ',', ' ', '(', ')', '-', '+', '^', '*', '/'}, StringSplitOptions.RemoveEmptyEntries);
List <string> ans = new List<string>();
foreach(var str in lst)
{
if(str[0]>='A' && str[0]<='Z' && str[str.Length-1]>='0' && str[str.Length-1]<='9')
{
ans.Add(str);
}
}
return ans;
}
public static Tuple<int, int> NameToCoordinates(string s)
{
int i=0, x=0, y=0;
while(s[i]>='A' && s[i]<='Z')
{
x=x*26+Convert.ToInt32(s[i]-65+1);
i++;
}
int j = i;
while(i<s.Length && s[i]>='0' && s[i]<='9')
{
y = y*10+Convert.ToInt32(s[i]-48);
i++;
}
return new Tuple<int, int>(x, y);
}
public static int Convert26To10(string s)
{
int i=0, x=0;
while(i<s.Length && s[i]>='A' && s[i]<='Z')
{
x=x*26+Convert.ToInt32(s[i]-65+1);
i++;
}
if(i!=s.Length)
{
throw new ArgumentException("Invalid argument");
}
return x;
}
}
}