码迷,mamicode.com
首页 > 其他好文 > 详细

逻辑代码题:如果昨天是明天,那今天就是周五了

时间:2017-11-09 19:44:37      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:amp   write   switch   nbsp   mon   console   col   pre   blog   

题目:I wish yesterday is tomorrow, then today is Friday. What is the actual date today?

思路:1.我希望昨天是明天,也就是说 假设的昨天 是 实际的明天 : yesterday=tomorrow

   2.实际的明天 就是 假设的今天-1 : tomorrow=today-1

   3. 假设的今天是周五:today=5

 1         //wish today is 5,so wish yesterday is 4 .actual tomorrow = wish yesterday
 2         public static void WhatIsToday()
 3         {
 4             int[] name = new int[3];
 5            
 6             for ( name[0] = 1; name[0] < 8; name[0]++)
 7             {
 8                 for (name[1] = 1; name[1] < 8; name[1]++)
 9                 {
10                     for (name[2] = 1; name[2] < 8; name[2]++)
11                     {
12                         if (name[1] == 5 && name[2] == name[1] - 1 && name[0] == name[2])
13                         {
14                             int today = name[2] - 1;
15                             string day = "";
16                             switch (today)
17                             {
18                                 case 1:
19                                     day = "Monday";
20                                     break;
21                                 case 2:
22                                     day = "Tuesday";
23                                     break;
24                                 case 3:
25                                     day = "Wednesday";
26                                     break;
27                                 case 4:
28                                     day = "Thursday";
29                                     break;
30                                 case 5:
31                                     day = "Friday";
32                                     break;
33                                 case 6:
34                                     day = "Satursday";
35                                     break;
36                                 case 7:
37                                     day = "Sunday";
38                                     break;
39                             }
40                             Console.WriteLine("today is " + day);
41                         }
42                     }
43                 }
44             }
45         }

 结果:

today is Wednesday

 

逻辑代码题:如果昨天是明天,那今天就是周五了

标签:amp   write   switch   nbsp   mon   console   col   pre   blog   

原文地址:http://www.cnblogs.com/hehe625/p/7810760.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!