A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续 判断第二个字母,第三个字母,直到可以判断出为止
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;

  5. namespace exam3
  6. {
  7.     class Program
  8.     {
  9.         //请输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续 判断第二个字母
  10.         static void Main(string[] args)
  11.         {
  12.             string[] week = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
  13.             int index = 0;//索引字母
  14.             int  IsFirst=0 ; //输入字母在星期中出现的次数
  15.             List<string>tempStr=new List<string>();//储存星期
  16.             while (true)
  17.             {
  18.                 Console.Write("请输入:");
  19.                 string str = Console.ReadLine().Trim();//去掉空格
  20.                
  21.                 for (int i = 0; i < week.Length&&index==0; i++)
  22.                 {
  23.                     //string  a=week[i].Substring(index).ToUpper();
  24.                     if (str.ToUpper()==week[i].Substring(index,1).ToUpper().ToString())//输入的字符是否与某星期的字母匹配
  25.                     {
  26.                         IsFirst++;
  27.                         tempStr.Add(week[i]);//将相同位置上相同的字母的星期存放在tenpStr中
  28.                      
  29.                     }

  30.                 }
  31.                
  32.                 for(int i=0;i<tempStr.Count&&index>=1;i++)//从tempStr中比较
  33.                 {
  34.                     if (str.ToUpper().Equals(tempStr[i].Substring(index, 1).ToUpper()))
  35.                     {
  36.                         IsFirst++;
  37.                         tempStr[0] = tempStr[i];
  38.                     }
  39.                     else
  40.                         tempStr.RemoveAt(i);
  41.                        
  42.                 }
  43.                 if (IsFirst == 1)//此字母只出现了一次
  44.                     break;
  45.                 index++;
  46.                 IsFirst = 0;//重新输入一个字母,将IsFirst置0
  47.                
  48.             }
  49.             Console.WriteLine("Today is :"+tempStr[0]);
  50.             Console.ReadKey();

  51.         }
  52.     }
  53. }
复制代码

4 个回复

正序浏览
{:soso_e112:}
回复 使用道具 举报
{:soso_e179:}
回复 使用道具 举报
值得学习ing!
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马