-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1343.cpp
More file actions
76 lines (73 loc) · 1.17 KB
/
1343.cpp
File metadata and controls
76 lines (73 loc) · 1.17 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
// 1343. 폴리오미노
// 2019.05.18
// 그리디 알고리즘
#include<iostream>
#include<string>
using namespace std;
string ans="";
bool flag=true;
void Calc(int cnt) // 폴리오미노를 덮는 함수
{
int tmp = cnt;
// 폴리오미노로 덮을 수 없는 경우
if(cnt%2==1)
{
flag=false;
return;
}
// 폴리오미노로 덮을 수 있는 경우
// 사전순으로 출력하는것이므로 4칸일땐 AAAA, 2칸일땐 BB를 저장한다.
while(tmp>0)
{
for(int i=0;i<tmp/4;i++) // AAAA로 덮을때
{
ans+="AAAA";
}
tmp%=4;
for(int i=0;i<tmp/2;i++) // BB로 덮을 때
{
ans+="BB";
}
tmp%=2;
}
}
int main()
{
string s;
cin>>s;
int cnt=0;
for(int i=0;i<s.size();i++)
{
if(s[i]=='X') // X의 개수 저장
{
cnt++;
if(i==s.size()-1)
{
// 끝이라면 폴리오미노를 덮음
Calc(cnt);
}
}
else if(s[i]!='X')
{
if(cnt!=0)
{
Calc(cnt);
cnt=0;
ans+='.';
}
else
{
ans+='.';
}
}
}
if(flag)
{
cout<<ans<<endl;
}
else
{
cout<<"-1"<<endl;
}
return 0;
}