Help us understand the problem. What is going on with this article?

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

More than 5 years have passed since last update.

概要

テスト投稿してみる。
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());
        }
    }
}
Schoner
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした