-
Notifications
You must be signed in to change notification settings - Fork 23
/
A.cpp
executable file
·46 lines (39 loc) · 869 Bytes
/
A.cpp
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
/*
Problem Statement: https://www.facebook.com/codingcompetitions/hacker-cup/2020/qualification-round/problems/A
Time: O(n²)
Space: O(n)
Author: Mohammed Shoaib, github.com/Mohammed-Shoaib
*/
#include <iostream>
#include <string>
using namespace std;
void travel_restrictions(int N, string& I, string& O) {
// go through each flight
for (int i = 0; i < N; i++) {
string flight(N, 'N');
flight[i] = 'Y';
for (int j = i + 1; j < N; j++) {
if (O[j - 1] == 'N' || I[j] == 'N')
break;
flight[j] = 'Y';
}
for (int j = i - 1; j >= 0; j--) {
if (O[j + 1] == 'N' || I[j] == 'N')
break;
flight[j] = 'Y';
}
cout << flight << endl;
}
}
int main() {
int T;
cin >> T;
for (int x = 1; x <= T; x++) {
int N;
string I, O;
cin >> N >> I >> O;
cout << "Case #" << x << ": " << endl;
travel_restrictions(N, I, O);
}
return 0;
}