2018年4月13日 星期五

Lucky貓 一顆星_3

Lucky貓 - Q11541: Decoding

編碼是把一段訊息由一種格式轉換成另一種格式,目前存在許多種編碼方式,本題要處理的是一種稱為"紀錄重複次數編碼"(Run-Length Encoding)的簡易編碼方式。

"紀錄重複次數編碼"是一種簡單易懂的資料壓縮方式,它把連續出現的字元以該字元及其重複次數來取代,例如AAA表示A連續出現3次,故以A3來取代 AAA。另一個例子是"AABBBBDAA"換成"A2B4D1A2"。

本題要求把編碼後的字串轉回原來的字串(即進行解碼)。
Input
輸入的第一列為整數 T ( T < 50 ),表示測試資料的組數,每組測試資料有一列字串,表示被編碼後的字串,該字串只會出現數字[0-9],及大寫字母[A-Z]。所有的字串必定是正確的編 碼字串。
Output
請輸出每組測試資料的編號及解碼後的字串, 格式如下。
編碼後的字串長度不會超過200個字元。


Sample Input                              Output for Sample Input

3
A2B4D1A2
A12
A1B1C1D1
Case 1: AABBBBDAA
Case 2: AAAAAAAAAAAA
Case 3: ABCD


            int N = int.Parse(Console.ReadLine());
            for (int i = 0; i < N; i++)
            {
                string input = Console.ReadLine() + "G", rememberS = null, rememberI = null, Collect = null;
                foreach (char item in input.ToCharArray())
                {
                    if (Convert.ToInt32(item) >= 65 && Convert.ToInt32(item) <= 90)
                    {
                        if (rememberI != null && rememberS != null)
                        {
                            for (int k = 0; k < int.Parse(rememberI); k++)
                                Collect = Collect + rememberS;
                            rememberS = rememberI = null;
                        }
                        rememberS = rememberS + item.ToString();
                    }
                    else rememberI = rememberI + item.ToString();
                }
                Console.WriteLine(Collect);
            }

Lucky貓 - Q11689: Soda Surpler

Tim 是一個非常愛喝汽水的人。由於他沒有錢,所以他要喝汽水的唯一方法就是收集空汽水瓶子,然後拿去回收換取錢再去買新汽水來喝。除了他自己喝完的空瓶子,Tim也會到街上去收集別人喝完的空瓶子。有一天,他非常的渴,他要盡可能的喝汽水,直到他得不到任何一瓶為止。
Input
輸入的第1列有一個整數N,代表以下有多少組測試資料。
每組測試資料1列,含有 3 個整數  e,f,c 。e(0 <=  e < 1000)代表Tim一開始擁有的空瓶子數目,f(0 <=  f < 1000)代表Tim在這一天他在街上收集到的空瓶子數目,c(1 <  c < 2000)代表多少個空瓶子可以換一瓶新的汽水。
請參考Sample Input。
Output
對每一組測試資料輸出一列,代表 Tim 可以喝到多少瓶汽水。
Sample InputSample Output
2
9 0 3
5 5 2
4
9



            int N = int.Parse(Console.ReadLine());
            for (int i = 0; i < N; i++)
            {
                int e = int.Parse(Console.ReadLine());
                int f = int.Parse(Console.ReadLine());
                int c = int.Parse(Console.ReadLine());
                int cola = 0;
                e = e + f;
                while (e >= c)
                {
                    f = e % c;
                    e = e / c;
                    cola = cola + e;
                    e = e + f;
                }
                Console.WriteLine("{0}\n\n",cola);
            }

N 個元素集合中所有的子集合共有 2N 
例如:N = 3 集合的元素假設為 {0, 1, 2}
所有的子集合包括空集合應該有下列 23=8 個:
{}
{0}
{1}
{2}
{0, 1}
{0, 2}
{1, 2}
{0, 1, 2}

        static void Main(string[] args)
        {
            int N = 0, start = 0, M;
            string[] s = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
            List<string> OriData = new List<string>(s);//Original
            List<string> CalData = new List<string>();//Calculate
            List<string> ColData = new List<string>(s);//Collect
            while (N < s.Length)
            {               
                int distance = ColData.Count - start;
                CalData = ColData.GetRange(start, distance);
                start = ColData.Count;
                for (int i = 0; i < CalData.Count; i++)
                {
                    char[] c = CalData[i].ToCharArray();
                    M = OriData.IndexOf(c[c.Length - 1].ToString());
                    for (int j = M + 1; j < OriData.Count; j++)
                        ColData.Add(CalData[i] + OriData[j]);
                }
                N++;
                ColData.TrimExcess();
                CalData.TrimExcess();
            }
            foreach (string item in ColData) Console.Write(item + " ");
            Console.WriteLine();
            Console.WriteLine("ColData : " + ColData.Capacity);
            Console.ReadLine();
        }




2018年4月8日 星期日

Lucky貓 一顆星_2

Lucky貓 - Q10924: Prime Words

質數就是一個數字只有兩個因數:1和自己,例如:1,2,3,5,17,101和10007都是質數。
在這問題中你需要讀入一組文字,每個字是由 a-z 和 A-Z 組成,每個字母都有他的值,字母 a 值 1,字母 b 值 2 ... 到字母 z 值 26,同樣的字母 A 值 27,B 值 28, Z 值 52。
你應該要寫個程式來檢查這組字是不是prime word,如果這組文字的字母值總和為質數的話,他就是 prime word。
Input
輸入含有多組測試資料,每組一列,且有 L (1 <= L <= 20)個字母。請參考Sample Input。
Output
對每一組字,如果它是 prime word 的話,輸出 "It is a prime word."。否則,請輸出 "It is not a prime word."。
Sample InputSample Output
UFRN
contest
AcM
a
A
It is a prime word.
It is not a prime word.
It is not a prime word.
It is a prime word.
It is not a prime word.
Translated by Link
            while (true)
            {
                string input = Console.ReadLine(), start = null;
                if (input == "") return;
                int sum = 0;
                foreach (char c in input)
                {
                    if ((c >= 65 && c <= 90) || (c >= 97 && c <= 122))
                    {
                        if (c < 91) sum = sum + Convert.ToInt32(c) - 38;
                        else sum = sum + Convert.ToInt32(c) - 96;
                    }
                }
                double SqrtSum = Math.Sqrt(sum);
                bool b = true;
                for (double i = 2; i <= SqrtSum; i++)
                    if (sum % i == 0)
                    {
                        b = false;
                        break;
                    }
                if (b) Console.WriteLine("It is a prime word.");
                else Console.WriteLine("It is not a prime word.");
            }
        }

Q11059: Maximum Product

給一個數字集合 { S1,S2, … ,Sn },請從這個數字集合裡找出一段連續數字,使他們的乘積是最大的。以Case 1為例子,2 x 4 = 8為這個集合的最大乘積;而Case 2則為2 x 5 x (–1) x 2 x (–1) =20。如果你找到的最大乘積小於等於0,則最後答案應輸出0

Input

每組測試資料開頭為一個正整數 1 ≤ N ≤ 18代表這個集合有幾個數字。每個數字 Si 都是範圍 -10 ≤ Si ≤ 10的整數。下一列則為這個集合的N個數字。各組測試資料之間都有一個空白列。請用EOF判斷檔案結束。

Output

每組測試資料印出一列: “Case #M: The maximum product is P.”。其中M代表測資的編號(從1開始計數),而 P代表的則是集合的最大乘積。每組測試資料後面請印出一行空白列。

Sample Input
Sample Output
3
2 4 -3
 
5
2 5 -1 2 -1
 
3
-9 -7 -8
 
2
1 -1
 
1
-9
Case #1: The maximum product is 8.
 
Case #2: The maximum product is 20.
 
Case #3: The maximum product is 63.
 
Case #4: The maximum product is 1.
 
Case #5: The maximum product is 0.
 
 
 
 
 
Translated by TimeString
            while (true)
            {
                int N = Convert.ToInt32(Console.ReadLine());
                List<int> Collect = new List<int>();
                int Max = 1;
                for (int i = 0; i < N; i++)
                {
                    int temp = Convert.ToInt32(Console.ReadLine());
                    if (i == 0) Max = temp;
                    else                   
                        if (Max * temp > Max) Max *= temp;                   
                }
                if (Max > 0) Console.WriteLine("Max = {0}\n\n", Max);
                else
                {
                    Console.WriteLine(0);
                    return;
                }
            }


Sample Input
Sample Output
3
2 4 -3
 
5
2 5 -1 2 -1
 
3
-9 -7 -8
 
2
1 -1
 
1
-9

2
0 3

0
Case #1: Max: 8, Min: -24
 
Case #2: Max: 20, Min: -20
 
Case #3: Max: 72, Min: -504
 
Case #4: Max: 1, Min: -1
 
Case #5: Max: -9, Min: -9
 
Case #6: Max: 3, Min: 0 
 
 
 



        static void Main(string[] args)
        {
            int Item = 1;
            while (true)
            {
                int N = int.Parse(Console.ReadLine()), Max = 1, Min = 1;
                List<int> RemindPlus = new List<int>(), RemindLess = new List<int>();
                switch (N)
                {
                    case 0:
                        return;
                    case 1:
                        Max = Min = int.Parse(Console.ReadLine());
                        break;
                    default:
                        for (int i = 0; i < N; i++)
                        {
                            int input = int.Parse(Console.ReadLine());
                            if (input > 0) RemindPlus.Add(input);
                            if (input < 0) RemindLess.Add(input);
                        }
                        RemindPlus.Sort();
                        RemindLess.Sort();
                        if (RemindPlus.Count == 0 && RemindLess.Count == 1) Max = 0;
                        else
                        {
                            foreach (int item in RemindPlus) Max = Max * item;
                            if (RemindLess.Count % 2 == 0)
                                foreach (int item in RemindLess) Max = Max * item;
                            else
                                for (int i = 0; i < RemindLess.Count - 1; i++)
                                    Max = Max * RemindLess[i];
                        }
                        if (RemindLess.Count == 0)
                        {
                            if (RemindPlus.Count != N) Min = 0;
                            else Min = RemindPlus[0];
                        }
                        else
                        {
                            foreach (int item in RemindPlus) Min = Min * item;
                            if (RemindLess.Count % 2 == 1)
                                foreach (int item in RemindLess) Min = Min * item;
                            else
                                for (int i = 0; i < RemindLess.Count - 1; i++)
                                    Min = Min * RemindLess[i];
                        }
                        break;
                }
                Console.WriteLine("Case #{0}: Max: {1}, Min: {2}\n", Item, Max, Min);
            }
        }


Q11219:  How old are you?


- 請填寫這張表格。
- 謝謝你,我幫你檢查一下…嗯…OK, OK, OK…咦?等等,請問你幾歲?
- 20歲,我忘了填上去了嗎?
- 不是,只是你不可能下個月才會出生吧!你的出生年寫錯了!
- 喔,對不起!
本題會給定現在的日期與某人的出生日期,請你幫忙檢查日期是不是寫錯,若沒錯請幫忙計算歲數。
Input
輸入的第一列會有一個整數T(1 <= T <= 200)表示測試資料的組數,接下來每組會有一個空行、現在的日期與出生日期,格式為DD/MM/YYYY,DD表示日期,MM為月份,YYYY表示西元 年。
Output
輸出請依下格式輸出: "Case #NAGE",N表示測試資料編號,AGE表示下 列三種可能:
  • "Invalid birth date",表示一個不可能的年紀,例如還沒出生。
  • "Check birth date",表示年紀大於130歲。
  • 一個整數表示年紀。
Sample InputSample Output
4

01/01/2007
10/02/2007

09/06/2007
28/02/1871

12/11/2007
01/01/1984

28/02/2005
29/02/2004
Case #1: Invalid birth date
Case #2: Check birth date
Case #3: 23
Case #4: 0








中文翻譯轉載自:Ruby 兔的ACM園地
範例
             DateTime LastSalaryDay = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 6);
           DateTime NextSalaryDay = new DateTime(DateTime.Now.AddMonths(1).Year, DateTime.Now.AddMonths(1).Month, 5);
            Console.WriteLine();
            System.Console.WriteLine("上次發薪日: {0} ", LastSalaryDay.ToString("yyyy/MM/dd"));
            TimeSpan ts1 = DateTime.Now - LastSalaryDay;
            Console.WriteLine("距離上次發薪日已過了{0}", ts1.Days);
            System.Console.WriteLine("下次發薪日: {0} ", NextSalaryDay.ToString("yyyy/MM/dd"));
            //用大的日期 減小的日期
            // TimeSpan ts2 =NextSalaryDay - DateTime.Now;
            TimeSpan ts2 = DateTime.Now - NextSalaryDay;   //小的日期減大的日期        
            Console.WriteLine("距離下次發薪日還有{0}", Math.Abs(ts2.Days)); //距離幾天一定是正的 用Math.Abs取絕對值
            System.Console.ReadLine();
---------------------------------------------------------------------------------------------------
          成品
             int N = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine();
            for (int i = 1; i <= N; i++)
            {
                string[] Now = Console.ReadLine().Split('/');
                string[] Birth = Console.ReadLine().Split('/');
                DateTime NowDate = new DateTime(Int32.Parse(Now[2]), int.Parse(Now[1]), int.Parse(Now[0]));
                DateTime BirthDate = new DateTime(int.Parse(Birth[2]), int.Parse(Birth[1]), int.Parse(Birth[0]));
                TimeSpan span = NowDate - BirthDate;
                int Date = int.Parse(span.Days.ToString()) - 1;
                if (Date <= 0) Console.WriteLine("Case #{0}: Invalid birth date", i);
                else
                {
                    if ((Date / 365) >= 130) Console.WriteLine("Case #{0}: Check birth date", i);
                    else Console.WriteLine("Case #{0}: {1}", i, Date / 365);
                }
                Console.WriteLine();
            }


WinFormTb02

https://drive.google.com/drive/u/0/folders/1UwS9FZ3ELCOK6SAwirHrkxq3z_RSbxJt https://www.youtube.com/watch?v=k7IkIeww_U0&list=PLumjEWemD...