2016年10月20日 星期四

#00102_Ecological Bin Packing

題目


解法:(暴力破解><)

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

namespace CPE_3test
{
    class _00102_Ecological_Bin_Packing
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("請輸入資料來分組!");
            int[] a = new int[3], b = new int[3], c = new int[3];
            for (int intA = 0; intA < 2; intA++)
            {
                string[] stamp =(Console.ReadLine()).Split(' ');
                a[0] = Convert.ToInt32(stamp[0]);
                a[1] = Convert.ToInt32(stamp[1]);
                a[2] = Convert.ToInt32(stamp[2]);
                b[0] = Convert.ToInt32(stamp[3]);
                b[1] = Convert.ToInt32(stamp[4]);
                b[2] = Convert.ToInt32(stamp[5]);
                c[0] = Convert.ToInt32(stamp[6]);
                c[1] = Convert.ToInt32(stamp[7]);
                c[2] = Convert.ToInt32(stamp[8]);
            }
            delievery(a, b, c);
        }
        private static void delievery(int[] b, int[] g, int[] c)
        {
            int min = BGC(b, g, c);
            string msg = "BGC";
            if (min > BCG(b, g, c)) { min = BCG(b, g, c); msg = "BCG"; }
            if (min > GBC(b, g, c)) { min = GBC(b, g, c); msg = "GBC"; }
            if (min > GCB(b, g, c)) { min = GCB(b, g, c); msg = "GCB"; }
            if (min > CBG(b, g, c)) { min = CBG(b, g, c); msg = "CBG"; }
            if (min > CGB(b, g, c)) { min = CGB(b, g, c); msg = "CGB"; }
            Console.WriteLine(msg + " " + min);
        }
        private static int BGC(int[] b, int[] g, int[] c)
        {
            int sum = 0;
            sum = g[0] + c[0];
            sum += b[1] + c[1];
            sum += b[2] + g[2];
            return sum;
        }
        private static int BCG(int[] b, int[] g, int[] c)
        {
            int sum = 0;
            sum = g[0] + c[0];
            sum += b[1] + g[1];
            sum += b[2] + c[2];
            return sum;
        }
        private static int GBC(int[] b, int[] g, int[] c)
        {
            int sum = 0;
            sum = g[1] + c[1];
            sum += b[0] + c[0];
            sum += b[2] + g[2];
            return sum;
        }
        private static int GCB(int[] b, int[] g, int[] c)
        {
            int sum = 0;
            sum = g[1] + c[1];
            sum += b[2] + c[2];
            sum += b[0] + g[0];
            return sum;
        }
        private static int CBG(int[] b, int[] g, int[] c)
        {
            int sum = 0;
            sum = g[2] + c[2];
            sum += b[0] + c[0];
            sum += b[1] + g[1];
            return sum;
        }
        private static int CGB(int[] b, int[] g, int[] c)
        {
            int sum = 0;
            sum = g[2] + c[2];
            sum += b[1] + c[1];
            sum += b[0] + g[0];
            return sum;
        }
    }
}

2016年10月19日 星期三

#12602_Nice Licence Plates

附上:Lucky貓的翻譯


 C#解答:

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

namespace CPE_3test
{
    class _12602_car
    {
        public static void Main(string[] args)
        {
            char[] abc = new char[] { 'A', 'B', 'C', 'D', 'E', 'F',
                'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
                'R', 'S', 'T', 'U', 'V', 'W', 'Q', 'R', 'S', 'T', 'U',
                'V', 'W', 'X', 'Y', 'Z' };

            int count = Convert.ToInt32(Console.ReadLine());
            int sum = 0;
            string msg = "";
            for (int intA = 0; intA < count; intA++)
            {
                string[] stamp = Console.ReadLine().Split('-');
                char[] abcd = stamp[0].ToCharArray();
                for (int intB = 0; intB < abcd.Length; intB++)
                {
                    for (int intC = 0; intC < abc.Length; intC++)
                    {
                      if (abcd[intB] == abc[intC] && intB == 0) sum += intC * 26 * 26;
                        if (abcd[intB] == abc[intC] && intB == 1) sum += intC * 26 ;
                        if (abcd[intB] == abc[intC] && intB == 2) sum += intC ;

                    }
                }
                int num = Convert.ToInt32(stamp[1]);
                sum = sum - num;
                if (sum < 0) sum = sum * -1;
                if (msg != "") msg += Environment.NewLine;
                if (sum <= 100) msg += "nice";
                else msg += "not nice";
            }
            Console.WriteLine(msg);
        }
    }
}


2016年10月13日 星期四

#12149_Feynman

分級:1
分類:數學計算

題目:

Richard Phillips Feynman was a well known American physicist and a recipient of the
Nobel Prize in Physics. He worked in theoretical physics and also pioneered the field
of quantum computing. He visited South America for ten months, giving lectures and
enjoying life in the tropics. He is also known for his books "Surely You're Joking, Mr.
Feynman!" and "What Do You Care What Other People Think?", which include some
of his adventures below the equator.

His life-long addiction was solving and making puzzles, locks, and cyphers. Recently,
an old farmer in South America, who was a host to the young physicist in 1949,
found some papers and notes that is believed to have belonged to Feynman. Among
notes about mesons and electromagnetism, there was a napkin where he wrote a
simple puzzle: "how many different squares are there in a grid of N ×N squares?".
In the same napkin there was a drawing which is reproduced below, showing that,
for N=2, the answer is 5.


Input
The input contains several test cases. Each test case is composed of a single line,
containing only one integer N, representing the number of squares in each side of
the grid (1 ≤ N ≤ 100).
The end of input is indicated by a line containing only one zero.

Output
For each test case in the input, your program must print a single line, containing the
number of different squares for the corresponding input.

Sample Input
2
1
8
0
Sample Output
5
1
204

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

namespace CPE_test2
{
    class Feynman
    {
        static void Main(string[] args)
        {
            string number = "" ;
            int ans = 0;
            Console.WriteLine("請輸入數字");
            string msg = "";
            while (true)
            {
                number = Console.ReadLine();
                if (number == "0") break;
                ans = Convert.ToInt32(number);
                //if (ans < 1) Console.WriteLine("錯誤:輸入數字小於1!");
                //if (ans > 100) Console.WriteLine("錯誤:輸入數字大於100!");
                ans = repeat(ans);
                msg += ans + Environment.NewLine;
            }
            Console.WriteLine(msg);
        }
        ///遞迴
        public  static int repeat(int num)
        {
            if (num == 1) return 1;
            return repeat(num - 1) + num * num;
        }
    }
}

#00494_Kindergarten Counting Game

分級:1
分類:字元與字串

題目:

Everybody sit down in a circle. Ok. Listen to me carefully.
 “Woooooo, you scwewy wabbit!”
Now, could someone tell me how many words I just said?

Input 
Input to your program will consist of a series of lines, each line containing multiple words (at least one). A “word” is defined as a consecutive sequence of letters (upper and/or lower case).

Output 
Your program should output a word count for each line of input. Each word count should be printed on a separate line.

Sample Input
Meep Meep!
 I tot I taw a putty tat. I did! I did!
 I did taw a putty tat.
 Shsssssssssh ... I am hunting wabbits. Heh Heh Heh Heh ...

 Sample Output 
2
7
10
9




using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CPE_test
{
    public partial class CountWord : Form
    {
        public CountWord()
        {
            InitializeComponent();
            this.btnSumit.Click += new EventHandler(btnSumit_Click);
        }
        private void btnSumit_Click(object sender, EventArgs e)
        {
            string sOrigin = this.txtInput.Text;
            string[] sSpilebyRow = sOrigin.Split(new string[] {"\n"}, StringSplitOptions.RemoveEmptyEntries);
            int iCountWord = 0;
            for (int intA = 0; intA &lt; sSpilebyRow.Length; intA++)
            {
                iCountWord = 0;
                string[] snRow = sSpilebyRow[intA].Split(' ');
                for (int intB = 0; intB &lt; snRow.Length; intB++)
                {
                    if(judgword(snRow[intB]))iCountWord++;
                }
                this.txtOutput.Text += iCountWord + Environment.NewLine;
            }
        }
        /// </code><br />
        <summary><code>用來判斷字還是...</code></summary><code>
        public bool judgword(string sMsg)
        {
            int iNum = 0;
            char[] stamp = sMsg.ToCharArray();
            for (int intA = 0; intA &lt; sMsg.Length; intA++)
            {
                if ((stamp[intA] &gt;= 'a' &amp;&amp; stamp[intA] &lt;= 'z') || (stamp[intA] &gt;= 'A' &amp;&amp; stamp[intA] &lt;= 'Z'))
                {
                    iNum++;
                }
            }
            if (iNum &gt; 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}