2015年3月12日 星期四

[2015][Quiz][Week03] Quiz02 - 40075040H

01.
//可將程式碼放於此處,請至文章的html模式編輯
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test
{
    class Program
    {
        static public void CMP(int num)
        {
            int first, second;
            first = num / 100;
            second = num % 100;
            if (num == (first * first) + (second * second))
                Console.WriteLine(num);
        }
        
        static void Main(string[] args)
        {
           // int i;
            for (int i = 1000; i <= 9999; i++)
            {
                Program.CMP(i);
            }
            Console.Read();
        }
    }
}

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

namespace test2
{
    class Program
    {
        static void Main(string[] args)
        {
            int buffer, now, var, num, c = 0;
            now = 0;
            //scan=Convert.ToInt32 (Console.ReadLine());
            for (int scan = 100; scan <= 100000000; scan++)
            {
                buffer = scan;
                c = 0;
                now = 0;
                var = 100 * scan;
                num = scan;
                for (int i = 0; num > 0; i++)
                {
                    num = num / 100;
                    c++;
                }
                for (int i = 0; var > 0; i++)
                {
                    var = var / 100;
                    buffer = var % 100;
                    buffer = Convert.ToInt32(Math.Pow(Convert.ToDouble(buffer), Convert.ToDouble(c)));

                    now += buffer;

                }
                if (scan == (now))
                    Console.WriteLine(scan);

            } Console.Read();
        }  
    }
}

沒有留言:

張貼留言