Skip to content

Instantly share code, notes, and snippets.

@DariusL
Created September 10, 2014 08:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DariusL/0e237675de1153964974 to your computer and use it in GitHub Desktop.
Save DariusL/0e237675de1153964974 to your computer and use it in GitHub Desktop.
WhyOhGodWhy
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WhyOhGodWhy
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)]
public class InfoAttribute : Attribute
{
public InfoAttribute(string author, long date = 0)
{
Name = author;
Version = 0;
Date = new DateTime(date);
}
public string Name { get; private set; }
public int Version { get; set; }
public DateTime Date { get; private set; }
public override string ToString()
{
string value = "Autorius : " + Name;
if (Version != 0)
{
value += " Versija : " + Version.ToString();
value += " Data : " + Date.ToString();
}
return value;
}
}
abstract class Figura
{
protected string str;
public override string ToString()
{
Type type = GetType();
var attr = type.GetCustomAttributes(true).Select(a => a as InfoAttribute).Single(a => a != null);
return String.Format("Figura : {0} {1}\r\nPlotas:{2}", type.Name, attr, str);
}
}
[Info("Darius", 635459460465359526, Version = -5)]
class Trikampis : Figura
{
public Trikampis(string input)
{
var split = input.Split(new char[] { ' ' });
var a = Convert.ToInt32(split[1]);
var b = Convert.ToInt32(split[2]);
var c = Convert.ToInt32(split[3]);
var p = a + b + c;
str = Convert.ToString(Math.Sqrt(p * (p - a) * (p - b) * (p - c)));
}
}
[Info("Darius", 635459460465359526, Version = -5)]
class Kvadratas : Figura
{
public Kvadratas(string input)
{
var split = input.Split(new char[] { ' ' });
var a = Convert.ToInt32(split[1]);
str = Convert.ToString(a * a);
}
}
[Info("Darius", 635459460465359526, Version = -5)]
class Staciakampis : Figura
{
public Staciakampis(string input)
{
var split = input.Split(new char[] { ' ' });
var a = Convert.ToInt32(split[1]);
var b = Convert.ToInt32(split[2]);
str = Convert.ToString(a * b);
}
}
[Info("Darius", 635459460465359526, Version = -5)]
class Apskritimas : Figura
{
public Apskritimas(string input)
{
var split = input.Split(new char[] { ' ' });
var a = Convert.ToInt32(split[1]);
str = Convert.ToString(Math.PI * a * a);
}
}
[Info("Darius", 635459460465359526, Version = -5)]
class Rombas : Figura
{
public Rombas(string input)
{
var split = input.Split(new char[] { ' ' });
var a = Convert.ToInt32(split[1]);
var b = Convert.ToInt32(split[2]);
str = Convert.ToString(a * b / 2);
}
}
[Info("Darius", 635459460465359526, Version = -5)]
class Trapecija : Figura
{
public Trapecija(string input)
{
var split = input.Split(new char[] { ' ' });
var a = Convert.ToInt32(split[1]);
var b = Convert.ToInt32(split[2]);
var c = Convert.ToInt32(split[3]);
str = Convert.ToString((a + b) / 2 * c);
}
}
class Program
{
static void Main(string[] args)
{
var stuff = DoStuff(System.IO.File.ReadAllText("duom.txt"));
foreach (var thing in stuff)
Console.WriteLine(thing);
Console.ReadLine();
}
static ArrayList DoStuff(string input)
{
var ret = new ArrayList();
var lines = input.Split(new char[] { '\n' });
foreach (var line in lines)
{
if(line.StartsWith("Trikampis"))
ret.Add(new Trikampis(line));
if (line.StartsWith("Kvadratas"))
ret.Add(new Kvadratas(line));
if (line.StartsWith("Staciakampis"))
ret.Add(new Staciakampis(line));
if (line.StartsWith("Apskritimas"))
ret.Add(new Apskritimas(line));
if (line.StartsWith("Rombas"))
ret.Add(new Rombas(line));
if (line.StartsWith("Trapecija"))
ret.Add(new Trapecija(line));
}
return ret;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment