-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathConstellation_Problem.cpp
More file actions
91 lines (82 loc) · 2.45 KB
/
Constellation_Problem.cpp
File metadata and controls
91 lines (82 loc) · 2.45 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
Three characters {#, *, .} represents a constellation of stars and galaxies in space. Each galaxy is demarcated by # characters. There can be one or many stars in a given galaxy. Stars can only be in the shape of vowels {
A
,
E
,
I
,
O
,
U
A,E,I,O,U}. A collection of * in the shape of the vowels is a star. A star is contained in a 3×3 block. Stars cannot be overlapping. The dot(.) character denotes empty space.
Given
3
×
N
3×N matrix comprising of { #, *, . } character, find the galaxy and stars within them.
Note: Please pay attention to how vowel A is denoted in a
3
×
3
3×3 block in the examples section below.
Input Format
Input consists of a single integer
N
N denoting the number of columns.
Output Format
The output contains vowels (stars) in order of their occurrence within the given galaxy. The galaxy itself is represented by the # character.
Constraints
3
≤
N
≤
1
0
5
3≤N≤10
5
// ---------------------------- SOLUTION ------------------------------ //
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;cin>>n;
char co[3][n];
for(int i=0;i<3;i++)
{
for(int j=0;j<n;j++)
cin>>co[i][j];
}
for(int i=0;i<n-2;i++)
{
if(co[0][i]=='#') {cout<<"#";continue;}
if(co[0][i]=='.' && co[0][i+1]=='*' && co[0][i+2]=='.')
{
if(co[1][i]=='*' && co[1][i+1]=='*' && co[1][i+2]=='*')
if(co[2][i]=='*' and co[2][i+1]=='.' and co[2][i+2]=='*')
cout<<"A";i+=2;continue;
}
if(co[0][i]=='*' and co[0][i+1]=='*' and co[0][i+2]=='*')
{
if (co[1][i]=='*' and co[1][i+1]=='*' and co[1][i+2]=='*')
{
if (co[2][i]=='*' and co[2][i+1]=='*' and co[2][i+2]=='*')
{cout<<"E";i+=2;continue;}
}
else if(co[1][i]=='.' and co[1][i+1]=='*' and co[1][i+2]=='.')
{
if (co[2][i]=='*' and co[2][i+1]=='*' and co[2][i+2]=='*')
{cout<<"I";i+=2;continue;}
}
else if(co[1][i]=='*' and co[1][i+1]=='.' and co[1][i+2]=='*')
{
if(co[2][i]=='*' and co[2][i+1]=='*' and co[2][i+2]=='*')
{cout<<"O";i+=2;continue;}
}
}
if(co[0][i]=='*' and co[0][i+1]=='.' and co[0][i+2]=='*')
if(co[1][i]=='*' and co[1][i+1]=='.' and co[1][i+2]=='*')
if(co[2][i]=='*' and co[2][i+1]=='*' and co[2][i+2]=='*')
{cout<<"U";i+=2;continue;}
}
}