求助,c#程序问题
原题目:编写控制台应用程序,判断用户输入的字符串中是否存在重复的由两个小写字母组成的子串,如有则按从左到右的出现顺序输出重复出现的子串及出现的次数;如果用户输入的字符串中包含非小写字母则输出“Inputting illegal characters”。
我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PTA1_5
{
class Program
{
static void Main(string[] args)
{
int n = 0;//记录出现重复词汇的个数
string[] words = new string[20];//保存出现的重复词汇
int[] times = new int[20];//每一个重复词汇出现的次数
string str1 = Console.ReadLine();
int b = str1.Length;
bool flag = true;
for (int i = 0; i < b; i++)
{
if (!Char.IsLower(str1[i]))
flag = false;
}
if (flag)
{
for (int i = 0; i < str1.Length - 2; i++)
{
bool isName = false;
string str2 = str1.Substring(i, 2);
int j = i + 1;
while (j < str1.Length -1)
{
string target = str1.Substring(j, 2);
if (str2 == target)
{
times[n]++;
if (Array.IndexOf(words, target) == -1)
{
words[n] = target;
isName = true;
}
}
j++;
}
if (isName) n++;
}