-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.cpp
124 lines (114 loc) · 2.7 KB
/
main.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
/**
*
* @Name : CheckReverseString/main.cpp
* @Version : 1.0
* @Programmer : Max
* @Date : 2018-07-13
* @Released under : https://github.com/BaseMax/CheckReverseString/blob/master/LICENSE
* @Repository : https://github.com/BaseMax/CheckReverseString
*
**/
#include <iostream>
#include <cstring>
// #include <algorithm>
using namespace std;
// reverse
string flip(string input) {
// reverse(input.begin(), input.end());
int length = input.length();
for(int index = 0; index < length / 2; index++)
swap(input[index], input[length - index - 1]);
return input;
}
void flip2(string& input) {
int length = input.length();
for(int index = 0; index < length / 2; index++)
swap(input[index], input[length - index - 1]);
}
char* flip3(char *input) {
size_t length = strlen(input);
char* temp = (char*) malloc(sizeof(char) * length + 1);
int counter = 0;
for(int index = length - 1; index >= 0; index--, counter++)
temp[counter] = input[index];
temp[counter + 1] = '\0';
return temp;
}
char* flip4(const char *input) {
size_t length = strlen(input);
char* temp = (char*) malloc(sizeof(char) * (length + 1));
if(temp) {
size_t counter = 0;
while(length > 0) {
length--;
temp[counter] = input[length];
counter++;
}
temp[counter] = '\0';
}
return temp;
}
char* flip5(char *input) {
size_t length = strlen(input);
size_t index = 0;
while (length > index) {
char tmp = input[--length];
input[len] = input[index];
input[index++] = tmp;
}
return input;
}
void flip6(string input) {
for(int index=input.length()-1; index>=0; index--)
cout << input[index];
}
char* flip7(char const* input) {
int length = strlen(input);
char *temp = new char[length+1];
strcpy(temp, input);
for(int index=0, counter=length-1; index<counter; index++,counter--)
swap(temp[index], temp[counter]);
return temp;
}
void flip8(string &input)
{
int length = input.length();
for(int index = 0; index < length/2; index++)
std::swap(input[index], input[length-index-1]);
}
void check(string input) {
const unsigned int size=input.length();
const unsigned int middle=size / 2;
bool result=true;
if(input.empty()) {
result=false;
}
cout << size << endl;
for(int index=0; index<middle; index++) {
if(input[index] == input[size-1-index]) {
// result=true;
continue;
}
else {
result=false;
break;
}
}
// cout << flip(input) << " (" << ((result == true) ? "TRUE" : "FALSE") << ")\n";
flip2(input);
cout << input << " (" << ((result == true) ? "TRUE" : "FALSE") << ")\n";
}
int main(int argc, char const *argv[]) {
string value;
cout << "Enter your value:\n";
while(true) {
cout << "> ";
cin >> value;
check(value);
if(value == "exit") {
break;
}
// check(name);
}
return 0;
}