-
Notifications
You must be signed in to change notification settings - Fork 0
/
70_B.cpp
88 lines (82 loc) · 1.32 KB
/
70_B.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
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
#include<iostream>
#include<vector>
#include<map>
#include<cmath>
#include<climits>
using namespace std;
bool found = false;
string s = "ROYGBIV";
string ans;
int n;
bool check(string s1)
{
int a[26]={0};
for(int i=0;i<s1.length();i++){
a[s1[i]-65]=1;
}
for(int i=0;i<s.length();i++){
if(a[s[i]-65]==0)
{
// cout<<s1<<" "<<(char)(s[i])<<endl;
return false;
}
}
// cout<<s1<<" ffef "<<endl;
for(int i=0;i<s1.length();i++){
int p[26]={0};
p[(s1[i])-65]++;
p[(s1[(i+1)%n])-65]++;
p[(s1[(i+2)%n])-65]++;
p[(s1[(i+3)%n])-65]++;
for(int j=0;j<26;j++){
if(p[j]>1)
{
// cout<<s1<<" eee "<<(char)(j+65)<<endl;
return false;
}
}
}
//ncout<<s1<<" ddd "<<s1<<endl;
return true;
}
void solve(char c1,char c2,char c3,string t)
{
// cout<<t<<endl;
if((int)t.length()>n || found)
return;
if((int)t.length()==n)
{
if(check(t) && !found)
{
ans = t;
found = true;
//cout<<ans<<endl;
return;
}
}
for(int i=0;i<s.length();i++){
if(s[i]!=c1 && s[i]!=c2 && s[i]!=c3)
{
solve(c2,c3,s[i],t+s[i]);
}
}
}
int main()
{
cin>>n;
for(int i=0;i<s.length();i++){
for(int j=i+1;j<s.length();j++){
for(int k=j+1;k<s.length();k++){
if(found)
break;
string t;
t+=s[i];
t+=s[j];
t+=s[k];
solve(s[i],s[j],s[k],t);
}
}
}
cout<<ans<<endl;
return 0;
}