-
Notifications
You must be signed in to change notification settings - Fork 5
/
My CSharp Template for Programming Contest.cs
151 lines (150 loc) · 4.27 KB
/
My CSharp Template for Programming Contest.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
using System;
using System.Text;
using System.Collections;
using System.Linq;
using System.Collections.Generic;
using System.Math;
/*
Leave the sleep and let the springtime talk
In tongues from the time before man
Listen to a daffodil tell her tale
Let the guest in, walk out, be the first to greet the morn
The meadows of heaven await harvest
The cliffs unjumped, cold waters untouched
The elsewhere creatures yet unseen
Finally your number came up, free fall awaits the brave
Come
Taste the wine, race the blind
They will guide you from the light
Writing noughts till the end of time
Come
Surf the clouds, race the dark
It feeds from the runs undone
Meet me where the cliff greets the sea
*/
namespace myCSharpTemplate
{
class MainClass
{
//Listen, I haven't test them all, but I think they are good enough.
//by Yuwono Bangun Nagoro a.k.a SurgicalSteel
const Double PI = 3.1415926535897932384626433832795;
const int MOD = 1000000007;
struct point{public int x; public int y;};
static int getsinglenum(string a)//converts a single string into decimal ASCII
{
byte[] dec = Encoding.ASCII.GetBytes(a);
return (int) dec[0];
}
static List<int> getallnum(string s)//converts whole string into decimal ASCII
{
var dec = Encoding.ASCII.GetBytes (s).ToList();
List<int> li = new List<int> ();
foreach (var i in dec)
{li.Add ((int)i);}
return li;
}
static bool isprime(int a) //this prime test function was originally authored by Egor Suvorov a.k.a yeputons and was written in C++
{
for (int i = 2; i * i <= a; i++)
{
if (a % i == 0)
{return false;}
}
return true;
}
static string eliminateAt(string x, int num)//eliminates a single substring of a string in a given position
{
if(num==0){return x.Substring(1,x.Length-1);}
else if(num==x.Length-1){return x.Substring(0,x.Length-1);}
else{return x.Substring(0,num)+x.Substring(num+1,x.Length-1);}
}
static string getstr(int a)//converts a decimal ASCII into a single string
{
char c = Convert.ToChar(a);
return c.ToString ();
}
static long pangkatp(int mybase,int exp) //powers base by exponent
{
if(exp==0){return 1;}
else{return mybase*pangkatp(mybase,exp-1);}
}
static long factorial(int num)//finds factorial of given integer
{
if (num == 0) {return 1;}
else {return num * factorial (num - 1);}
}
static int sumdigit(string a) //sums all digit on given string (if the string only contains digits)
{
int sum=0;
for(int x=0;x<a.Length;x++)
{
int tmp;
int.TryParse (a.Substring (x, 1), out tmp);
sum+=tmp;
}
return sum;
}
static string revstring(string s)
{
string build = "";
for (int i = s.Length - 1; i >= 0; i++)
{build += s.Substring (i, 1);}
return build;
}
static string tobase(int num,int mybase) //translates bitmask from decimal number to base n. 2<=n<=9
{
string a="";
while(num>0)
{
a+=(num%mybase).ToString();
num=(num-(num%mybase))/mybase;
}
return revstring(a);
}
static List<int> sieve(int n)
{
List<int> res=new List<int>();
int temp=1;
for(int i=2;i<=n;i++)
{
for(int a=2;a<=i;a++)
{if(i%a==0){temp++;}}
if(temp==2){res.Add(i);}
temp=1;
}
return res;
}
static int binarysearch(int[] a, int val) //requires a sorted vector, will return -1 if there's no such element exists in the vector
{
if (a.Length == 0) { return -1; }
int l = 0;
int r = a.Length - 1;
while (l < r)
{
int m = (l + r) / 2;
if (a[m] > val)
{
if(m==r){m--;}
r = m;
}
if (a[m] < val)
{
if(m==l){m++;}
l = m;
}
if(a[m]==val) { return m; }//return the index
}
return -1;
}
public static void Main (string[] args)
{
//string tmp;
//int tc;
//tmp = int.Parse(Console.ReadLine ());
//int.TryParse (tmp, out tc);
Console.WriteLine("Hello World!");
Console.ReadLine();
}
}
}