黑马程序员技术交流社区
标题:
自己写的输入一个字母来判断是星期几的程序
[打印本页]
作者:
熊丽
时间:
2013-8-10 17:09
标题:
自己写的输入一个字母来判断是星期几的程序
输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续 判断第二个字母,第三个字母,直到可以判断出为止
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace exam3
{
class Program
{
//请输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续 判断第二个字母
static void Main(string[] args)
{
string[] week = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
int index = 0;//索引字母
int IsFirst=0 ; //输入字母在星期中出现的次数
List<string>tempStr=new List<string>();//储存星期
while (true)
{
Console.Write("请输入:");
string str = Console.ReadLine().Trim();//去掉空格
for (int i = 0; i < week.Length&&index==0; i++)
{
//string a=week[i].Substring(index).ToUpper();
if (str.ToUpper()==week[i].Substring(index,1).ToUpper().ToString())//输入的字符是否与某星期的字母匹配
{
IsFirst++;
tempStr.Add(week[i]);//将相同位置上相同的字母的星期存放在tenpStr中
}
}
for(int i=0;i<tempStr.Count&&index>=1;i++)//从tempStr中比较
{
if (str.ToUpper().Equals(tempStr[i].Substring(index, 1).ToUpper()))
{
IsFirst++;
tempStr[0] = tempStr[i];
}
else
tempStr.RemoveAt(i);
}
if (IsFirst == 1)//此字母只出现了一次
break;
index++;
IsFirst = 0;//重新输入一个字母,将IsFirst置0
}
Console.WriteLine("Today is :"+tempStr[0]);
Console.ReadKey();
}
}
}
复制代码
作者:
许庭洲
时间:
2013-8-10 19:19
值得学习ing!
作者:
彭家贰小姐
时间:
2013-8-10 22:57
{:soso_e179:}
作者:
熊丽
时间:
2013-8-11 21:34
{:soso_e112:}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2