-
Notifications
You must be signed in to change notification settings - Fork 0
/
290.cs
59 lines (58 loc) · 1.9 KB
/
290.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Text;
namespace WordPattern
{
class WordPattern
{
private static bool GetDC(string pattern, string str)
{
char[] templates = pattern.ToCharArray();
string[] sArray = str.Split(' ');
char[templates.Length] temppattern;
string[templates.Length] tempword;
int count = 1;
if (sArray.Count()!=templates.Length)
{
return false;
}
temppattern[0]=templates[0];
tempword[0]=sArray[0];
for(i=1;i<templates.Length;i++)
{
for(j=0;j<count;j++)
{
if(temppattern[j]==templates[i])
{
if(tempword[j]!=sArray[i])
return false;
break;
}
else
{
if(tempword[j]==sArray[i])
return false;
}
if(j==(count-1))
{
temppattern[count]=templates[i];
tempword[count]=sArray[i];
count++;
break;
}
}
}
return true;
}
static void main(string[] args)
{
Console.WriteLine("請輸入Pattern(格式為一串小寫字母,每個字母代表一個單字):");
string template = Console.ReadLine();
Consloe.WriteLIne("請輸入一段文字,裡面每個單字的所有字母都是小寫,單字與單字中間用空白隔開:");
string tempstring = Console.ReadLine();
if(GetDC(template,tempstring))
Console.Write("True");
else
Console.Write("False");
}
}
}