-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLongestPost.java
More file actions
29 lines (29 loc) · 985 Bytes
/
LongestPost.java
File metadata and controls
29 lines (29 loc) · 985 Bytes
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
import java.util.Scanner;
public class LongestPost {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true){
int N = sc.nextInt();
if (N == 0) break;
String[] strs = new String[N];
for (int i = 0; i < N; i++){
strs[i] = sc.next();
}
StringBuilder sb = new StringBuilder();
for (int i = 1; i <= strs[0].length(); i++){
char c = strs[0].charAt(strs[0].length()-i);
boolean flag = true;
for (int j = 1; j < N; j++){
if (i > strs[j].length() || strs[j].charAt(strs[j].length()-i) != c){
flag = false;
break;
}
}
if (flag)
sb.append(c);
else break;
}sb.reverse();
System.out.println(sb);
}
}
}