Skip to content

Commit

Permalink
initial commit of several book sources
Browse files Browse the repository at this point in the history
  • Loading branch information
alecnunn committed Dec 22, 2018
0 parents commit 4562f64
Show file tree
Hide file tree
Showing 33,041 changed files with 7,971,872 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.zip
*.dll
*.obj
*.a
*.exe
*.mov
*.avi
*.mpg
*.mpeg
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.IO;
using System.Text.RegularExpressions;

namespace EMailRegExp
{
/// <summary>
/// Summary description for Class.
/// </summary>
class Class
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
StreamReader sr = new StreamReader(args[0], System.Text.Encoding.Default);
string text = sr.ReadToEnd();
sr.Close();

Regex r = new Regex("\\b[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\\.[a-zA-Z]{2,4}\\b");
MatchCollection mc = r.Matches(text);

foreach(Match m in mc)
Console.WriteLine(m.Value);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
And now it is time to say goodbye!
--
With best regards, Masha Petrova
(����[email protected])


And now it is time to say goodbye!
--
With best regards, Masha Petrova
([email protected])
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Text.RegularExpressions;

namespace NumRegExp
{
/// <summary>
/// Summary description for Class.
/// </summary>
class Class
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
string s;
Regex r = new Regex("\\A-?[0-9]+(.[0-9]+)?\\z");

while((s = Console.ReadLine()) != "")
Console.WriteLine(r.Matches(s).Count == 1);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.IO;
using System.Text.RegularExpressions;

namespace GreedyLazyRE
{
/// <summary>
/// Summary description for Class.
/// </summary>
class Class
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
StreamReader sr = new StreamReader(args[0], System.Text.Encoding.Default);
string text = sr.ReadToEnd();
sr.Close();

Regex r1 = new Regex("1\\..+\\d\\d\\d-\\d\\d\\d\\d", RegexOptions.Singleline);
Regex r2 = new Regex("\\[imp].*?\\[/imp]", RegexOptions.Singleline);

Match m = r1.Match(text);
Console.WriteLine(m.Value);
Console.WriteLine();

MatchCollection mc = r2.Matches(text);
foreach(Match mt in mc)
Console.WriteLine(mt.Value.Substring(5, mt.Value.Length - 11));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(beginning of phonebook)
1. Smith 123-4567
2. Jones 234-5678
3. Brown 345-6789
(end of phonebook)

This text might be interesting, and even very interesting. But it is not important at all.
[imp]And this text is extremely boring; but there is nothing we can do -- it is important![/imp]
Here is the section of humour...
[imp]And here is the protocol of committee JX1321 meeting, dated 11.05.2004[/imp]
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.IO;
using System.Text.RegularExpressions;

namespace EMailChange
{
/// <summary>
/// Summary description for Class.
/// </summary>
class Class
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
StreamReader sr = new StreamReader(args[0], System.Text.Encoding.Default);
string text = sr.ReadToEnd();
sr.Close();

Regex r = new Regex("\\b(?<user>[a-zA-Z0-9_.-]+)@" +
"(?<server>[a-zA-Z0-9._-]+)" +
"\\.(?<domain>[a-zA-Z]{2,4})\\b");
string result = r.Replace(text, "${user} at ${server} dot ${domain}");

StreamWriter sw = new StreamWriter("new " + args[0], false, System.Text.Encoding.Default);
sw.Write(result);
sw.Close();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;

namespace EMailDFA
{
/// <summary>
/// Summary description for Class.
/// </summary>
class Class
{
/// <summary>
/// The main entry point for the application.
/// </summary>

enum StateType { s1, s2, s3, s4, s5, sF };
enum CommandType { cMain, cDot, cAt, cEnd };

struct SC
{
public StateType state;
public CommandType command;
public SC(StateType state_, CommandType command_)
{
state = state_;
command = command_;
}
}

static CommandType convertCommand(char c)
{
if((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
(c >= '0' && c <= '9') || (c == '_' || c == '-'))
return CommandType.cMain;
if(c == '@') return CommandType.cAt;
if(c == '.') return CommandType.cDot;

return CommandType.cEnd;
}

static void Main(string[] args)
{
string Tape = Console.ReadLine() + '\0';
StateType State = StateType.s1;
CommandType Command;

Dictionary<SC, StateType> Automaton = new Dictionary<SC, StateType>();
Automaton.Add(new SC(StateType.s1, CommandType.cMain), StateType.s2);
Automaton.Add(new SC(StateType.s2, CommandType.cMain), StateType.s2);
Automaton.Add(new SC(StateType.s2, CommandType.cAt), StateType.s3);
Automaton.Add(new SC(StateType.s3, CommandType.cMain), StateType.s4);
Automaton.Add(new SC(StateType.s4, CommandType.cMain), StateType.s4);
Automaton.Add(new SC(StateType.s4, CommandType.cDot), StateType.s5);
Automaton.Add(new SC(StateType.s5, CommandType.cMain), StateType.sF);
Automaton.Add(new SC(StateType.sF, CommandType.cMain), StateType.sF);
Automaton.Add(new SC(StateType.sF, CommandType.cDot), StateType.s5);


try
{
while(true)
{
Console.WriteLine("State: " + State.ToString());

Command = convertCommand(Tape[0]);
Tape = Tape.Substring(1);

if(Command == CommandType.cEnd)
break;

State = Automaton[new SC(State, Command)];
}
}
catch(Exception)
{
Console.WriteLine("Incorrect transition");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
using System;
using System.Collections.Generic;

namespace DFAMinimization
{
/// <summary>
/// Summary description for Class.
/// </summary>
class Class
{
/// <summary>
/// The main entry point for the application.
/// </summary>

struct Pair // a pair of states
{
public int P, Q;
public Pair(int thep, int theq) { P = thep; Q = theq; }
}

struct Leftside // a left side of a rule -- a pair (state, symbol)
{
public int State;
public char Symbol;
public Leftside(int st, char sym) { State = st; Symbol = sym; }
}

struct DFA
{
public int StatesCount;
public char[] Symbols;
public bool[] IsFavorable;
public int FavorableState;
public int StartState;
public Dictionary<Leftside, int> Rules;
}

static DFA readInput()
{
DFA dfa;
dfa.StatesCount = Convert.ToInt32(Console.In.ReadLine());

string symbols_str = Console.In.ReadLine();
dfa.Symbols = symbols_str.ToCharArray(0, symbols_str.Length);

string[] favorable_list = (Console.In.ReadLine()).Split(' ');
dfa.IsFavorable = new bool[dfa.StatesCount + 1];
foreach(string id in favorable_list)
dfa.IsFavorable[Convert.ToInt32(id)] = true;

dfa.StartState = Convert.ToInt32(Console.In.ReadLine());
dfa.FavorableState = Convert.ToInt32(favorable_list[0]);

dfa.Rules = new Dictionary<Leftside, int>();
string s;
while((s = Console.In.ReadLine()) != "")
{
string[] tr = s.Split(' ');
dfa.Rules.Add(new Leftside(Convert.ToInt32(tr[0]), Convert.ToChar(tr[1])), Convert.ToInt32(tr[2]));
}

return dfa;
}

static Dictionary<Pair, bool> setupMarkedPairs(DFA dfa)
{
Dictionary<Pair, bool> pairs = new Dictionary<Pair, bool>();

for(int i = 1; i <= dfa.StatesCount; ++i)
for(int j = 1; j <= dfa.StatesCount; ++j)
{
bool Marked = ((dfa.IsFavorable[i] == true && dfa.IsFavorable[j] == false) ||
(dfa.IsFavorable[i] == false && dfa.IsFavorable[j] == true));
pairs.Add(new Pair(i, j), Marked);
}

return pairs;
}

static void processPairs(DFA dfa, Dictionary<Pair, bool> pairs)
{
bool found;
do
{
found = false;
foreach(KeyValuePair<Pair, bool> pair in pairs)
{
if(pair.Value == false)
foreach(char a in dfa.Symbols)
{
int d1 = dfa.Rules[new Leftside(pair.Key.P, a)];
int d2 = dfa.Rules[new Leftside(pair.Key.Q, a)];

if(pairs[new Pair(d1, d2)] == true)
{
pairs[new Pair(pair.Key.P, pair.Key.Q)] = true;
found = true;
goto exit;
}
}
}

exit: ;
}
while(found);
}

static int[] createEqClasses(DFA dfa, Dictionary<Pair, bool> pairs)
{
int[] e_class = new int[dfa.StatesCount + 1];
for(int i = 1; i <= dfa.StatesCount; ++i)
e_class[i] = i;

foreach(KeyValuePair<Pair, bool> pair in pairs)
if(pair.Value == false)
for(int i = 1; i <= dfa.StatesCount; ++i)
if(e_class[i] == pair.Key.P)
e_class[i] = pair.Key.Q;
return e_class;
}

static void outputResults(DFA dfa, Dictionary<Pair, bool> pairs, int[] e_class)
{
Dictionary<int, bool> states = new Dictionary<int, bool>();
for(int state = 1; state <= dfa.StatesCount; ++state)
states[e_class[state]] = true;

Dictionary<string, bool> rules = new Dictionary<string, bool>();
foreach(KeyValuePair<Leftside, int> rule in dfa.Rules)
{
string rule_str = "(" + e_class[rule.Key.State].ToString() + ", " +
rule.Key.Symbol.ToString() + ") -> " + e_class[rule.Value].ToString();

rules[rule_str] = true;
}

Console.Write("States: ");
foreach(KeyValuePair<int, bool> state in states)
Console.Write("{0} ", state.Key);

Console.WriteLine();
Console.WriteLine("Initial state: {0}\nFavorable state: {1}",
e_class[dfa.StartState], e_class[dfa.FavorableState]);

Console.WriteLine("Rules:");
foreach(KeyValuePair<string, bool> rule in rules)
Console.WriteLine(rule.Key);
}

static void Main(string[] args)
{
DFA dfa = readInput();

Dictionary<Pair, bool> pairs = setupMarkedPairs(dfa);
processPairs(dfa, pairs);

int[] e_class = createEqClasses(dfa, pairs);

outputResults(dfa, pairs, e_class);
}
}
}
Loading

0 comments on commit 4562f64

Please sign in to comment.