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

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

ABC146で書いたコード

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

namespace Atcoder20190616
{
    class ProgramA
    {
        static void Main(string args)
        {
            //数値入力する
            string input = Console.ReadLine();

            //それぞれの文字列で答えを出す
            if(input == "SUN")
                Console.WriteLine("7");
            else if(input == "MON")
                Console.WriteLine("6");
            else if(input == "TUE")
                Console.WriteLine("5");
            else if(input == "WED")
                Console.WriteLine("4");
            else if(input == "THU")
                Console.WriteLine("3");
            else if(input == "FRI")
                Console.WriteLine("2");
            else if(input == "SAT")
                Console.WriteLine("1");
                
        }
    }

    class ProgramB
    {
        static void Main(string args)
        {
            
            //入力
            string input = Console.ReadLine();
            int n = int.Parse(input);

            string s = Console.ReadLine();

            //char型で読み込み、int型に変換。そこから数を足して、char型に戻す
            for(int i = 0;i < s.Length;i++)
            {
                int c = Convert.ToInt32(s[i]); //charをintにする
                int temp = c + n; //n文字進める
                if(temp > 90) //ZをAに戻す。
                    c += n - 26;
                else
                    c += n;

                Console.Write*1; //答え出力
            }

            
                
        }
    }

    class ProgramC
    {
        static void Main(string args)
        {
            
            //入力
            string input = Console.ReadLine().Split();
            long a = long.Parse(input[0]);
            long b = long.Parse(input[1]);
            long x = long.Parse(input[2]);


            //自明な答えは省く(a+bより小さい金額なら買えない)
            if(a+b > x)
            {
                Console.WriteLine("0");
                return;
            }
            //自明な答えは省く(以下の条件では一番大きい整数が買える)
            if(a * 1000000000 + b * 10 <= x)
            {
                Console.WriteLine("1000000000");
                return;
            }

            //一番かかる場合を出す。最小は0とする
            long max = 1000000000;
            long min = 0;
            long keta = 0;
            long temp = 0;
            
            //二分探索法。
            while(max != min + 1)
            {
                //とりあえず真ん中の数でそれより大きいか小さいかを探す
                temp = (max + min/2;
                
                //ここまでの数の桁数を特定する
                for(long i = 9;i >= 1;i--)
                {
                    long temp2 = temp / (long)Math.Pow(10i - 1);
                    if(0 < temp2 && temp2 < 10)
                    {
                        keta = i;
                        break;
                    }
                }

                //実際の金額を求めて、満たすなら最小、満たさないなら最大にする
                if(a * temp + b * keta > x)
                    max = temp;
                else
                    min = temp;

            }
            
            //答え出力
            Console.WriteLine(min);
                
        }
    }
          
}

*1:char)(c