東大卒のお金やりくり奮闘記~株、家計、趣味、経済~

東大卒でメーカー勤務の私がセミリタイアするために投資などを頑張っていこうという趣旨で始めたブログです。既婚男性です。株、家計、趣味、経済の話をメインにゆるゆる話します。

ABC155で書いたコード

using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;

namespace Atcoder20190616
{
    class ProgramA
    {
        static void Main(string args)
        {
            //入力
            string input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            int c = int.Parse(input[2]);

            //2つの数が同じでもう一つが異なればYes,それ以外はno
            if(a == b && a != c)
                Console.WriteLine("Yes");
            else if(a == c && a != b)
                Console.WriteLine("Yes");
          else if(b == c && b != a)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
            
        }
    }

    class ProgramB
    {
        static void Main(string args)
        {
            
            //入力
            int n = int.Parse(Console.ReadLine());
            string input = Console.ReadLine().Split(' ');
 
            //すべての和を求める
            for(int i = 0;i < n ;i++)
            {
                int temp = int.Parse(input[i]);

                //偶数かつ3でも5でも割れない数があれば拒否
                if(temp % 2 == 0)
                {
                    if(temp % 3 != 0 && temp % 5 != 0)
                    {
                        Console.WriteLine("DENIED");
                        return;
                    }
                }
            }

            //すべての数を満たせば承認
            Console.WriteLine("APPROVED");
    
        }
    }

    class ProgramC
    {
        static void Main(string args)
        {
            
            //入力
            int n = int.Parse(Console.ReadLine());
            Dictionary<stringintmap = new Dictionary<stringint>();
            int max = 0;
 
 
            for(int i = 0i < n;i++)
            {
                string input = Console.ReadLine();
                try
                {//ないときは加える
                    map.Add(input1);
                }
                catch
                {//エラーが起こると存在しているので足す
                    map[input]++;
                }

                //一番大きい数は求めておく
                if(map[input] > max)
                    max = map[input];
                    
            }

            //一番大きい数選んで、リスト化する
            var keys = map.Where(x => x.Value == max).Select(x => x.Key).ToList();
            //keyをアルファベット順に並べる(このときカッコ内があると計算が早くなる)
            keys.Sort(StringComparer.OrdinalIgnoreCase);
            //出力する
            foreach (var s in keys)
            {
                Console.WriteLine(s);
            }
        } 
    }   

    class ProgramE
    {
        static void Main(string args)
        {
            
            //入力
            string n = Console.ReadLine();
            int num = n.Length;
            
            //一桁あげた場合をdp_plus、あげない場合をdpとする
            int dp_plus = new int[num];
            int dp = new int[num];

            for(int i = 0i < num;i++)
            {
                //代入
                int temp = n[i] - '0';
                //一桁あげた場合とあげなかった場合
                if(i == 0)
                {
                    dp[i] = temp;
                    dp_plus[i] = 11 - temp;
                }
                else
                {
                    //一桁あげなかった場合は単純にtempを足す
                    dp[i] = Math.Min(dp[i-1]+temp,dp_plus[i-1]+temp);
                    //一桁あげた場合は、一桁前をあげてない場合11-temp、あげた場合は9-tempとなる
                    dp_plus[i] = Math.Min(dp[i-1]+11-temp,dp_plus[i-1]+9-temp);
                }
            }

            //あげたケースとあげなかったケースで小さい方を選ぶ
            Console.WriteLine(Math.Min(dp[num -1],dp_plus[num -1]);
   
        } 
    }
    
}