結果

問題 No.55 正方形を描くだけの簡単なお仕事です。
ユーザー nanophoto12nanophoto12
提出日時 2014-11-03 01:50:06
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 30 ms / 5,000 ms
コード長 3,058 bytes
コンパイル時間 1,013 ms
コンパイル使用メモリ 107,648 KB
実行使用メモリ 19,072 KB
最終ジャッジ日時 2024-04-26 22:04:47
合計ジャッジ時間 2,601 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
18,816 KB
testcase_01 AC 27 ms
18,944 KB
testcase_02 AC 27 ms
18,816 KB
testcase_03 AC 30 ms
18,944 KB
testcase_04 AC 27 ms
18,688 KB
testcase_05 AC 27 ms
18,688 KB
testcase_06 AC 27 ms
18,688 KB
testcase_07 AC 26 ms
18,944 KB
testcase_08 AC 26 ms
19,072 KB
testcase_09 AC 26 ms
18,944 KB
testcase_10 AC 27 ms
18,688 KB
testcase_11 AC 27 ms
18,688 KB
testcase_12 AC 27 ms
18,944 KB
testcase_13 AC 27 ms
19,072 KB
testcase_14 AC 27 ms
18,944 KB
testcase_15 AC 27 ms
18,816 KB
testcase_16 AC 27 ms
18,944 KB
testcase_17 AC 27 ms
18,816 KB
testcase_18 AC 26 ms
18,816 KB
testcase_19 AC 28 ms
18,560 KB
testcase_20 AC 27 ms
18,944 KB
testcase_21 AC 27 ms
18,816 KB
testcase_22 AC 27 ms
18,944 KB
testcase_23 AC 26 ms
18,816 KB
testcase_24 AC 27 ms
18,816 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Linq;

class Program
{
    public class Point
    {
        private readonly int _x;
        private readonly int _y;

        public Point(int x, int y)
        {
            _x = x;
            _y = y;
        }

        public int X
        {
            get { return _x; }
        }

        public int Y
        {
            get { return _y; }
        }
    }

    public static int DistanceSquare(Point first, Point second)
    {
        var dx = first.X - second.X;
        var dy = first.Y - second.Y;
        return dx * dx + dy * dy;
    }

    private static Point ToVector(Point first, Point second)
    {
        return new Point(second.X - first.X, second.Y - first.Y);
    }

    private static bool IsDiagnostic(Point firstVector, Point secondVector)
    {
        if (firstVector.X * secondVector.X + firstVector.Y * secondVector.Y == 0)
        {
            return true;
        }
        return false;
    }

    private static Point CreateFourth(Point opposite, Point lineStart, Point lineEnd)
    {
        var x = opposite.X + ((lineStart.X + lineEnd.X)  - opposite.X * 2);
        var y = opposite.Y + ((lineStart.Y + lineEnd.Y)  - opposite.Y * 2);
        return new Point(x, y);
    }


    public static void Main(string[] args)
    {
        var values = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        Point[] points = new Point[3];
        points[0] = new Point(values[0], values[1]);
        points[1] = new Point(values[2], values[3]);
        points[2] = new Point(values[4], values[5]);
        if (DistanceSquare(points[0], points[1]) == DistanceSquare(points[1], points[2]))
        {
            if (!IsDiagnostic(ToVector(points[1], points[0]), ToVector(points[2], points[1])))
            {
                Console.WriteLine(-1);
                return;
            }
            var fourth = CreateFourth(points[1], points[0], points[2]);
            Console.WriteLine("{0} {1}", fourth.X, fourth.Y);
            return;

        }
        if (DistanceSquare(points[0], points[2]) == DistanceSquare(points[1], points[2]))
        {
            if (!IsDiagnostic(ToVector(points[2], points[0]), ToVector(points[2], points[1])))
            {
                Console.WriteLine(-1);
                return;
            }
            var fourth = CreateFourth(points[2], points[0], points[1]);
            Console.WriteLine("{0} {1}", fourth.X, fourth.Y);
            return;
        }
        if (DistanceSquare(points[0], points[1]) == DistanceSquare(points[0], points[2]))
        {
            if (!IsDiagnostic(ToVector(points[1], points[0]), ToVector(points[2], points[0])))
            {
                Console.WriteLine(-1);
                return;
            }
            var fourth = CreateFourth(points[0], points[2], points[1]);
            Console.WriteLine("{0} {1}", fourth.X, fourth.Y);
            return;
        }
        Console.WriteLine(-1);
    }
}
0