-
Notifications
You must be signed in to change notification settings - Fork 0
/
rotate_string.cpp
48 lines (44 loc) · 1.03 KB
/
rotate_string.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
// =====================================================================================
//
// Filename: rotate_string.cpp
//
// Description: 796. Rotate String.
//
// Version: 1.0
// Created: 08/15/2019 10:02:18 AM
// Revision: none
// Compiler: g++
//
// Author: Zhu Xianfeng (), [email protected]
// Organization:
//
// =====================================================================================
#include <stdio.h>
#include <string>
using std::string;
class Solution
{
public:
bool rotateString(string& a, string& b)
{
if (a.size() != b.size())
{
return false;
}
string c = a + a;
return (c.find(b) != string::npos);
}
};
int main(int argc, char* argv[])
{
string a = "abcde";
string b = "cdeab";
if (argc > 2)
{
a = argv[1];
b = argv[2];
}
bool ok = Solution().rotateString(a, b);
printf("%s, %s -> %s\n", a.c_str(), b.c_str(), (ok ? "true" : "false"));
return 0;
}