-
-
Notifications
You must be signed in to change notification settings - Fork 110
/
Abbreviation.java
48 lines (46 loc) · 1.17 KB
/
Abbreviation.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
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int q=sc.nextInt();
sc.nextLine();
while(q--!=0){
String s1=sc.nextLine();
String s2=sc.nextLine();
String s=s1.toUpperCase();
char a[]=s.toCharArray();
char b[]=s2.toCharArray();
char c[]=s1.toCharArray();
System.out.println((count(c,b)&&order(a,b))?"YES":"NO");
}
}
public static boolean count(char c[],char b[]){
int l1=c.length;
int l2=b.length;
int n=0;
for(int i=0;i<l1;i++){
if(c[i]>=65&&c[i]<=90)
n++;
}
if(n>l2)
return false;
return true;
}
public static boolean order(char a[],char b[]){
int l1=a.length;
int l2=b.length;
int f=0;
for(int i=0;i<l1;i++){
if(a[i]==b[f]){
f++;
if(f==l2)
return true;
}
}
return false;
}
}