Skip to content

Instantly share code, notes, and snippets.

@Sander-Kastelein
Created December 17, 2015 12:35
Show Gist options
  • Save Sander-Kastelein/e13e3ddd3782316d2508 to your computer and use it in GitHub Desktop.
Save Sander-Kastelein/e13e3ddd3782316d2508 to your computer and use it in GitHub Desktop.
csharp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
TextReader myfile = File.OpenText("file1.txt");
TextWriter newfile = File.CreateText("output1.txt");
string output = String.Concat(myfile.ReadToEnd().Reverse());
newfile.Write(output);
Console.WriteLine(output);
TextReader myfile2 = File.OpenText("file2.txt");
string line;
while((line = myfile2.ReadLine()) != null)
{
if(line.Contains("void"))
{
Console.WriteLine(line);
}
}
TextReader myfile3 = File.OpenText("file3.txt");
TextWriter newfile3 = File.CreateText("output3.txt");
int i = 1;
while ((line = myfile3.ReadLine()) != null)
{
newfile3.WriteLine("{0:D5}{1}", i, " " + line);
Console.WriteLine(String.Format("{0:D5}{1}", i, " " + line));
i++;
}
newfile3.Close();
TextReader myfile4 = File.OpenText("output3.txt");
TextWriter newfile4 = File.CreateText("output4.txt");
while ((line = myfile4.ReadLine()) != null)
{
List<string> lineS = line.Split(' ').ToList();
lineS.RemoveAt(0);
string newStr = string.Join(" ", lineS.ToArray());
newfile4.WriteLine(newStr);
Console.WriteLine(newStr);
}
TextReader myfile5 = File.OpenText("file4.txt");
TextWriter newfile5 = File.CreateText("output5.txt");
Dictionary<string, int> lines = new Dictionary<string, int>();
while ((line = myfile5.ReadLine()) != null)
{
string sline = line.Substring(23);
string[] numbersS = sline.Split(' ');
int[] numbers = new int[numbersS.Length];
for(int k = 0; k < numbersS.Length; k++)
{
try {
numbers[k] = int.Parse(numbersS[k]);
}
catch(Exception e)
{
}
}
line += " " + numbers.Sum();
lines.Add(line, numbers.Sum());
newfile5.WriteLine(line);
Console.WriteLine(line);
}
var sortedDict = from entry in lines orderby entry.Value ascending select entry;
int pos = 0;
int lastVal = -1;
foreach (KeyValuePair<string, int> entry in sortedDict)
{
if(lastVal != entry.Value)
{
pos++;
}
Console.WriteLine("Position " + pos + " " + entry.Key);
}
Console.Read();
}
}
}
@somaria
Copy link

somaria commented Dec 30, 2015

May I know what is this program doing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment