forked from chencorey/HackerRank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbbreviation.cpp
More file actions
49 lines (47 loc) · 968 Bytes
/
Abbreviation.cpp
File metadata and controls
49 lines (47 loc) · 968 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
37
38
39
40
41
42
43
44
45
46
47
48
49
// https://www.hackerrank.com/contests/world-codesprint-6/challenges/abbr
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
string word, target;
bool go(int a, int b)
{
if (b >= target.length())
{
for (int i = a; i < word.length(); i++)
{
if (word[i] >= 'A'&&word[i] <= 'Z')return false;
}
return true;
}
else
{
for (int i = a; i<word.length(); i++)
{
if (word[i] == target[b]) return go(i + 1, b + 1);
if (word[i] >= 'A'&&word[i] <= 'Z') return false;
if (toupper(word[i]) == target[b])
{
bool check = go(i + 1, b + 1);
if (check)return true;
}
}
}
return false;
}
int main() {
int cases;
cin >> cases;
for (int i = 0; i<cases; i++)
{
cin >> word;
cin >> target;
bool result = go(0, 0);
if (result)cout << "YES" << endl;
else cout << "NO" << endl;
}
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
return 0;
}