Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Shapes
- {
- struct size
- {
- public int H { get; set; }
- public int W { get; set; }
- public override string ToString()
- {
- return String.Format("{0} {1}", H, W);
- }
- public size(int a, int b)
- {
- H = a;
- W = b;
- }
- public static size operator +(size sz1, size sz2)
- {
- return new size(sz1.H + sz2.H, sz1.W + sz2.W);
- }
- }
- struct point
- {
- int x, y;
- public override string ToString()
- {
- return String.Format("{0} {1}", x, y);
- }
- public point(int a, int b)
- {
- x = a;
- y = b;
- }
- public point(size sz)
- {
- x = sz.H;
- y = sz.W;
- }
- public static point operator +(point pt, size sz)
- {
- return new point(pt.x + sz.H, pt.y + sz.W);
- }
- public static explicit operator size(point pt)
- {
- return new size(pt.x, pt.y);
- }
- }
- class SizeList
- {
- size[] s;
- public SizeList(size[] a)
- {
- s = a;
- }
- public static SizeList operator +(SizeList sl1, SizeList sl2)
- {
- size[] output = new size[sl1.s.Length];
- for (int i = 0; i < sl1.s.Length; i++)
- output[i] = sl1.s[i] + sl2.s[i];
- return new SizeList(output);
- }
- public System.Collections.IEnumerator GetEnumerator()
- {
- for (int i = 0; i < s.Length; i++)
- {
- yield return s[i];
- }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- size s1 = new size(5, 9);
- size s2 = new size(2, 1);
- Console.WriteLine(s1 + s2);
- point p1 = new point(3, 4);
- point p2 = new point(s2 + s1);
- Console.WriteLine(p2 + s2);
- SizeList szl1 = new SizeList(new size[]{ s1, s2 });
- SizeList szl2 = new SizeList(new size[] {(size)p1, (size)p2});
- foreach (size s in szl1)
- Console.Write(s + ";");
- Console.WriteLine();
- foreach (size s in szl2)
- Console.Write(s + ";");
- Console.WriteLine();
- foreach (size s in szl1 + szl2)
- Console.Write(s + ";");
- }
- }
- }
Add Comment
Please, Sign In to add comment