-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPanCard.java
More file actions
37 lines (30 loc) · 891 Bytes
/
PanCard.java
File metadata and controls
37 lines (30 loc) · 891 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
30
31
32
33
34
35
36
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class PanCard {
// Template Credit goes to www.hackerrank.com/kogupta
private static boolean isValidPAN(String s) {
String pattern = "^([A-Z]{5})(\\d{4})([A-Z]{1})$";
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(s);
if(m.matches()){
return true;
}
return false;
}
public static void main(String[] args) {
String s = null;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
int i = Integer.parseInt(br.readLine());
for (int j = 0; j < i; j++) {
s = br.readLine();
System.out.println(isValidPAN(s) ? "YES" : "NO");
}
} catch (IOException e) {
e.printStackTrace();
}
}
}