Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
2
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

@Schoner

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

概要

テスト投稿してみる。
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());
        }
    }
}
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
2
Help us understand the problem. What are the problem?