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...