Skip to content

Commit ba95fde

Browse files
Merge pull request #212 from Abostraous/patch-3
SimilarDishes.java
2 parents 701c624 + c6cd1e0 commit ba95fde

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import java.io.IOException;
2+
import java.util.Scanner;
3+
4+
public class SimilarDishes {
5+
6+
public static void main(String[] args) throws IOException {
7+
int t, i, j;
8+
t = Integer.parseInt(ConsoleInput.readToWhiteSpace(true));
9+
10+
for(i = 0; i < t; i++) {
11+
int count = 0;
12+
String[] s = new String[4];
13+
for(i = 0; i < 4; i++) {
14+
s[i] = ConsoleInput.readToWhiteSpace(true);
15+
}
16+
String[] a = new String[4];
17+
for ( i = 0;i < 4;i++) {
18+
a[i] = ConsoleInput.readToWhiteSpace(true);
19+
}
20+
for ( i = 0;i < 4;i++) {
21+
for (j = 0;j < 4;j++) {
22+
if (s[i].equals(a[j])){
23+
count++;
24+
}
25+
}
26+
}
27+
if (count >= 2) {
28+
System.out.print("similar");
29+
System.out.print("\n");
30+
}
31+
else {
32+
System.out.print("dissimilar");
33+
System.out.print("\n");
34+
}
35+
}
36+
}
37+
}
38+
39+
//Class for reading whitespace
40+
class ConsoleInput
41+
{
42+
private static boolean goodLastRead = false;
43+
public static boolean lastReadWasGood()
44+
{
45+
return goodLastRead;
46+
}
47+
48+
public static String readToWhiteSpace(boolean skipLeadingWhiteSpace) throws IOException
49+
{
50+
String input = "";
51+
char nextChar;
52+
while (Character.isWhitespace(nextChar = (char)System.in.read()))
53+
{
54+
55+
if (!skipLeadingWhiteSpace)
56+
{
57+
input += nextChar;
58+
}
59+
}
60+
61+
input += nextChar;
62+
63+
64+
while (!Character.isWhitespace(nextChar = (char)System.in.read()))
65+
{
66+
input += nextChar;
67+
}
68+
69+
goodLastRead = input.length() > 0;
70+
return input;
71+
}
72+
73+
public static String scanfRead() throws IOException
74+
{
75+
return scanfRead(null, -1);
76+
}
77+
78+
public static String scanfRead(String unwantedSequence) throws IOException
79+
{
80+
return scanfRead(unwantedSequence, -1);
81+
}
82+
83+
public static String scanfRead(String unwantedSequence, int maxFieldLength) throws IOException
84+
{
85+
String input = "";
86+
87+
char nextChar;
88+
if (unwantedSequence != null)
89+
{
90+
nextChar = '\0';
91+
for (int charIndex = 0; charIndex < unwantedSequence.length(); charIndex++)
92+
{
93+
if (Character.isWhitespace(unwantedSequence.charAt(charIndex)))
94+
{
95+
96+
while (Character.isWhitespace(nextChar = (char)System.in.read()))
97+
{
98+
}
99+
}
100+
else
101+
{
102+
103+
nextChar = (char)System.in.read();
104+
if (nextChar != unwantedSequence.charAt(charIndex))
105+
return null;
106+
}
107+
}
108+
109+
input = (new Character(nextChar)).toString();
110+
if (maxFieldLength == 1)
111+
return input;
112+
}
113+
114+
while (!Character.isWhitespace(nextChar = (char)System.in.read()))
115+
{
116+
input += nextChar;
117+
if (maxFieldLength == input.length())
118+
return input;
119+
}
120+
121+
return input;
122+
}
123+
}

0 commit comments

Comments
 (0)