forked from sakshamchecker/Hacktoberfest-21
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB_Prinzessin_der_Verurteilung.cpp
269 lines (253 loc) · 5.18 KB
/
B_Prinzessin_der_Verurteilung.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#include<bits/stdc++.h>
using namespace std;
int INF = 1000000005;
long long inf = 1000000000000000005LL;
#define sqr(x) ((ll)(x) * (x))
#define watch(x) cout<<#x<<" : "<<x<<endl
#define all(x) x.begin(), x.end()
#define len(v) v.size()
#define srt(v) sort( v.begin(), v.end())
#define rsrt(v) sort( v.rbegin(), v.rend())
#define rvrs(v) reverse( v.begin(), v.end())
#define rep(i, a, n) for(long long i = a; i < n; i++)
#define rep0(i, n) for(long long i = 0; i < n; i++)
#define rep1(i, n) for(long long i = 1; i <= n; i++)
#define repn(i, n) for(long long i = n-1;i >= 0;i--)
#define repstl(i,v) for(auto &i: v)
#define pb push_back
#define out(x) cout<<x<<"\n";
#define endl "\n"
#define outs(x) cout<<x<<" "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef pair<long long, long long> pl;
typedef pair<long long, pl> ppl;
typedef vector<long long> vl;
typedef vector<vector<long long>> vvl;
typedef vector<pair<long long, long long>> vll;
typedef vector<ppl> vlll;
typedef vector<string> vs;
ll mod = 1e9 + 7;
vector <ll> primes;
ll modoinv(ll a, ll m)
{
ll m0 = m;
ll y = 0, x = 1;
if (m == 1)
return 0;
while (a > 1) {
ll q = a / m;
ll t = m;
m = a % m, a = t;
t = y;
y = x - q * y;
x = t;
}
if (x < 0)
x += m0;
return x;
}
class Graph
{
map<ll , vector<pair<ll, ll>>> ma;
public:
void addedge(ll n, ll m, ll k)
{
ma[n].pb({m, k});
ma[m].pb({n, k});
}
vector<ll> solve()
{
vector<ll> ans;
sol(ans, 1, 1, 0, 1);
return ans;
}
void sol(vector<ll> &ans, ll node, ll count, ll dist, ll parent)
{
if ((node != 1) and (ma[node].size() == 1))
{
ans.pb(dist);
return;
}
for (auto pp : ma[node])
{
ll a = pp.first;
ll b = pp.second;
if (a != parent)
{
sol(ans, a, count + 1, dist + (count * b), node);
}
}
}
};
class Node
{
public:
char data;
unordered_map<char, Node*> children;
bool terminal;
Node(char d)
{
data = d;
terminal = false;
}
};
class Trie
{
public:
Node* root;
ll cnt;
Trie()
{
root = new Node('\0');
cnt = 0;
}
void insert(char *w)
{
Node* temp = root;
for (ll i = 0; w[i] != '\0'; i++)
{
char ch = w[i];
if (temp->children.count(ch))
{
temp = temp->children[ch];
}
else
{
Node* n = new Node(ch);
temp->children[ch] = n;
temp = n;
}
}
temp->terminal = true;
}
bool find(string w)
{
Node* temp = root;
for (ll i = 0; w[i] != '\0'; i++)
{
char ch = w[i];
if (temp->children.count(ch) == 0)
return false;
else
{
temp = temp->children[ch];
}
}
return temp->terminal;
}
};
vector<ll> primeFactors(ll n)
{
vector<ll> ans;
ll cur = 1;
ans.pb(1);
while (n % 2 == 0)
{
cur = cur * 2;
ans.pb(cur);
n = n / 2;
}
for (ll i = 3; i * i <= (n); i = i + 2)
{
while (n % i == 0)
{
cur = cur * i;
ans.pb(cur);
n = n / i;
}
}
if (n > 2)
ans.pb(cur * n);
return ans;
}
void sieve(ll p)
{
vector <bool> mark(p, 1);
for (ll i = 3; i < p; i += 2)
{
if (mark[i] == 1)
{
for (ll j = i * i ; j < p ; j += 2 * i)
{
mark[j] = 0;
}
}
}
primes.pb(2);
for (ll i = 3; i < p; i += 2)
{
if (mark[i])
primes.pb(i);
}
}
ll mod_exp(ll x, ll n, ll m)
{
//cout << x << " " << n << endl;
if (n == 0)
return 1 % m;
ll a = mod_exp(x, n / 2, m);
if (n % 2 == 0)
return (a * a) % m;
else
return (x * a * a) % m;
}
bool isPrime(ll n)
{
if (n == 1)
return 1;
if (n == 2)
return 1;
for (ll i = 2; i * i <= n; i++)
if (n % i == 0)
return 0;
return 1;
}
ll nc2(ll n)
{
if (n < 2)
return 0;
else
return ((n) * (n - 1)) / 2;
}
// 1. Take care of the corner cases, write one or two tests that seem to be the cases.
// 2. Check the bounds on the intput and decide the algorithm.
// 3. Make the test cases for the bounds, try to include 0, 1, 2 cases in the new test cases, and if possible, scale the cases.
// 4. Check for overflow and the array bounds carefully, always take care of the decreasing loop.
void solve(){
ll n;
cin>>n;
string s;
cin>>s;
// iterate on the length
//26*26*26 > 17000 > 1000 which is the constraint
rep(i,1 ,4){
ll num = 1;
rep(j,0,i){
num *= 26;
}
rep(mask , 0 , num){
string t;
ll temp = mask;
rep( j , 0 ,i){
ll d = temp % 26;
t.pb('a' + d);
temp /= 26;
}
reverse(all(t));
if(s.find(t) == -1){
out(t);
return ;
}
}
}
}
int main(){
fastio;
ll t=1;
cin>>t;
while(t--){
solve();
}
return 0;
}