LoginSignup
1
2

More than 5 years have passed since last update.

プログラミングコンテストチャレンジブック1-6.「三角形」

Last updated at Posted at 2015-05-12

概要

テスト投稿してみる。
C#で記述しています。

ソースコード

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Kai1_6Sankakukei
{
    class RunMain
    {
        public RunMain()
        {
        }
        public static int Main()
        {
            new RunMain().solve();
            return 0;
        }

        const int MAX_N = 100;
        Scanner cin;


        void solve()
        {
            // 入力フェイズ
            int ans = 0;
            cin = new Scanner();
            int n = cin.myInputInt();
            int[] a = new int[MAX_N];
            for (int i = 0; i < n; i++)
            {
                a[i] = cin.myInputInt();
            }

            // 演算フェイズ
            for (int i = 0; i < n; i++)
            {
                for (int j = i + 1; j < n; j++)
                {
                    for (int k = j + 1; k < n; k++)
                    {
                        int len = a[i] + a[j] + a[k];
                        int ma = Math.Max(a[i], Math.Max(a[j], a[k]));
                        int rest = len - ma;

                        if (ma < rest)
                        {
                            ans = Math.Max(ans, len);
                        }
                    }
                }
            }

            Console.WriteLine("{0}\n", ans);
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string myInput()
        {
            if (i < s.Length)
                return s[i++];
            string st = Console.ReadLine();
            while (st == "")
                st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return s[i++];
        }

        public int myInputInt()
        {
            return int.Parse(myInput());
        }

        public long myInputLong()
        {
            return long.Parse(myInput());
        }

        public double myInputDouble()
        {
            return double.Parse(myInput());
        }
    }
}
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2