-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalindrome.cpp
More file actions
106 lines (90 loc) · 2.02 KB
/
Palindrome.cpp
File metadata and controls
106 lines (90 loc) · 2.02 KB
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
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
class Stack{
private:
int stacksize=10;
int top;
char *stack;
public:
Stack(); // 생성자 초기화
void push(char num);
int pop();
int isEmpty();
int isFull();
void display();
};
Stack::Stack(){
top = -1;
stack = new char[stacksize];
}
void Stack::push(char num){
stack[++top] = num;
}
int Stack::pop(){
return stack[top--];
}
int Stack::isEmpty(){
if (top == -1)
return 0;
else {
return 1;
}
}
int Stack::isFull(){
if(top == stacksize-1){
cout<< "full"<<endl;
return 0;
}
else
{
cout<<"is not full"<<endl;
return 1;
}
}
void Stack::display(){
for(int i =0; i<top; i++){
cout<<stack[i]<<endl;
}
}
int main(){
ifstream infile;
infile.open("lab3.txt");
Stack s;
int i =0;
string str;
for(int j = 0 ; j < 4 ; j++){
infile >> str;
cout << str << endl;
if(str.size() % 2 == 0 ){
for(int i = 0 ; i < str.size()/2 ; i++){
// cout<< str[i]<<endl;
s.push(str[i]);
}
int j;
for(j = str.size()/2 ; j < str.size() ; j++){
if(str[j] == s.pop() ) continue;
else{
cout << "not" << endl;
break;
}
}
if(j == str.size()) cout << " valid" << endl;
}
else{
for(int i = 0 ; i < str.size()/2 ; i++){
s.push(str[i]);
}
int j;
for(j = str.size()/2 + 1 ; j < str.size() ; j++){
if(str[j] == s.pop() ) continue;
else{
cout << "not" << endl;
break;
}
}
if(j == str.size()) cout << " valid" << endl;
}
}
}