-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathCan_string_be_palindrome.cpp
44 lines (39 loc) · 1.03 KB
/
Can_string_be_palindrome.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
// Copyright (c) 2013 Elements of Programming Interviews. All rights reserved.
#include <cassert>
#include <iostream>
#include <random>
#include <string>
#include "./Can_string_be_palindrome_hash.h"
#include "./Can_string_be_palindrome_sorting.h"
using std::boolalpha;
using std::cout;
using std::default_random_engine;
using std::endl;
using std::random_device;
using std::string;
using std::uniform_int_distribution;
string rand_string(int len) {
string ret;
default_random_engine gen((random_device())());
while (len--) {
uniform_int_distribution<int> dis('a', 'z');
ret += dis(gen);
}
return ret;
}
int main(int argc, char *argv[]) {
default_random_engine gen((random_device())());
for (int times = 0; times < 1000; ++times) {
string s;
if (argc == 2) {
s = argv[1];
} else {
uniform_int_distribution<int> dis(1, 10);
s = rand_string(dis(gen));
}
cout << s << endl;
assert(can_string_be_a_palindrome_hash(s) ==
can_string_be_a_palindrome_sorting(&s));
}
return 0;
}