程式分為四個部分
Program 為程式進入點
PokerForm 為視窗主程式
CardDeck 為類別 建立一整副牌.進行重置.洗牌.依點數和花色大小排列
PokerCard 為類別 設定每張牌的點數.花色 以及轉換輸出
2015年4月6日 星期一
2015年4月5日 星期日
[2015][Homework]Team03 - Hw04
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace JugPuzzle
{
class Program
{
static void Main(string[] args)
{
start:
Console.WriteLine("請輸入水杯A");
int settingbottleA = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("請輸入水杯B");
int settingbottleB = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("請輸入要幾公升");
int settingtarget = Convert.ToInt32(Console.ReadLine());
int gcd = Program.gcd(settingbottleA, settingbottleB);
if ((settingtarget > settingbottleB) && (settingtarget > settingbottleA))
{
Console.WriteLine("要設定的公升比大水杯還大,永遠達不到,結束程式");
}
else
{
if (settingtarget % gcd == 0)
{
Program.jugPuzzle(settingbottleA, settingbottleB, settingtarget);
}
else
{
Console.WriteLine("此題無解");
}
}
Console.Read();
}
static int gcd(int m, int n) //最大公因數
{
int temp = 0;
while (n != 0)
{
temp = m % n;
m = n;
n = temp;
}
return m;
}
static void jugPuzzle(int settingbottleA, int settingbottleB, int settingbottletarget)
{
int bottleA = 0;
int bottleB = 0;
int delta;
do
{
if (bottleA == 0)
{
bottleA += settingbottleA;
Console.WriteLine("A杯子裝滿{0}公升", settingbottleA);
Console.WriteLine("目前狀態:(A杯子為{0}公升,B杯子為{1}公升)", bottleA, bottleB);
}
else if (bottleB == settingbottleB)
{
bottleB = 0;
Console.WriteLine("B杯子把水倒掉");
Console.WriteLine("目前狀態:(A杯子為{0}公升,B杯子為{1}公升)", bottleA, bottleB);
}
else if (bottleA == settingbottleA)
{
bottleA -= settingbottleA;
bottleB += settingbottleA;
if (bottleB > settingbottleB)
{
delta = bottleB - settingbottleB;
bottleB = settingbottleB;
bottleA = delta;
}
Console.WriteLine("A杯子往B杯倒水");
Console.WriteLine("目前狀態:(A杯子為{0}公升,B杯子為{1}公升)", bottleA, bottleB);
}
else
{
bottleB += bottleA;
if (bottleB > settingbottleB)
{
delta = bottleB - settingbottleB;
bottleB = settingbottleB;
bottleA = delta;
}
else
{
bottleA = 0;
}
Console.WriteLine("A杯子往B杯倒水");
Console.WriteLine("目前狀態:(A杯子為{0}公升,B杯子為{1}公升)", bottleA, bottleB);
}
} while ((bottleB != settingbottletarget)&&(bottleA != settingbottletarget));
}
}
}
2015年4月3日 星期五
[2015][Homework]Team06 - Hw05
程式分為四個部分
Program為主程式
Point為類別 點的x.y座標和到另一點的距離
PinBoard為類別 板子的大小.間距.創造點和設定點的位置
Triangle為類別 三個大頭針的位置.計算是否構成三角形.其周長.面積.外接圓半徑
Program為主程式
Point為類別 點的x.y座標和到另一點的距離
PinBoard為類別 板子的大小.間距.創造點和設定點的位置
Triangle為類別 三個大頭針的位置.計算是否構成三角形.其周長.面積.外接圓半徑
訂閱:
文章 (Atom)