-
Notifications
You must be signed in to change notification settings - Fork 0
/
CultureShock.java
98 lines (93 loc) · 3.03 KB
/
CultureShock.java
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import java.util.*;
import java.util.regex.*;
import java.text.*;
import java.math.*;
import java.awt.geom.*;
public class CultureShock
{
public String translate(String text)
{
String text2 = text;
do
{ text = text2;
text2 = text.replaceAll("^ZEE$", "ZED").replaceAll("^ZEE ", "ZED ").replaceAll(" ZEE$", " ZED").replaceAll(" ZEE ", " ZED ");
} while (!text2.equals(text));
return text;
}
public static void main(String[] args)
{
long time;
String answer;
boolean errors = false;
String desiredAnswer;
time = System.currentTimeMillis();
answer = new CultureShock().translate("THE TWENTY SIXTH LETTER OF THE ALPHABET IS ZEE");
System.out.println("Time: " + (System.currentTimeMillis()-time)/1000.0 + " seconds");
desiredAnswer = "THE TWENTY SIXTH LETTER OF THE ALPHABET IS ZED";
System.out.println("Your answer:");
System.out.println("\t\"" + answer + "\"");
System.out.println("Desired answer:");
System.out.println("\t\"" + desiredAnswer + "\"");
if (!answer.equals(desiredAnswer))
{
errors = true;
System.out.println("DOESN'T MATCH!!!!");
}
else
System.out.println("Match :-)");
System.out.println();
time = System.currentTimeMillis();
answer = new CultureShock().translate("ZEE");
System.out.println("Time: " + (System.currentTimeMillis()-time)/1000.0 + " seconds");
desiredAnswer = "ZED";
System.out.println("Your answer:");
System.out.println("\t\"" + answer + "\"");
System.out.println("Desired answer:");
System.out.println("\t\"" + desiredAnswer + "\"");
if (!answer.equals(desiredAnswer))
{
errors = true;
System.out.println("DOESN'T MATCH!!!!");
}
else
System.out.println("Match :-)");
System.out.println();
time = System.currentTimeMillis();
answer = new CultureShock().translate("SPELLING IN ENGLISH IS EZEE");
System.out.println("Time: " + (System.currentTimeMillis()-time)/1000.0 + " seconds");
desiredAnswer = "SPELLING IN ENGLISH IS EZEE";
System.out.println("Your answer:");
System.out.println("\t\"" + answer + "\"");
System.out.println("Desired answer:");
System.out.println("\t\"" + desiredAnswer + "\"");
if (!answer.equals(desiredAnswer))
{
errors = true;
System.out.println("DOESN'T MATCH!!!!");
}
else
System.out.println("Match :-)");
System.out.println();
time = System.currentTimeMillis();
answer = new CultureShock().translate("ZEE ZEE ZED ZEDS ZEE ZEES");
System.out.println("Time: " + (System.currentTimeMillis()-time)/1000.0 + " seconds");
desiredAnswer = "ZED ZED ZED ZEDS ZED ZEES";
System.out.println("Your answer:");
System.out.println("\t\"" + answer + "\"");
System.out.println("Desired answer:");
System.out.println("\t\"" + desiredAnswer + "\"");
if (!answer.equals(desiredAnswer))
{
errors = true;
System.out.println("DOESN'T MATCH!!!!");
}
else
System.out.println("Match :-)");
System.out.println();
if (errors)
System.out.println("Some of the test cases had errors :-(");
else
System.out.println("You're a stud (at least on the test data)! :-D ");
}
}
//Powered by [KawigiEdit]