-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab10.3.c
93 lines (82 loc) · 1.74 KB
/
lab10.3.c
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
#include <stdio.h>
#include <malloc.h>
typedef struct ListNode {
char val;
struct ListNode *next;
}Node;
int isPalindrome(Node *head);
Node* take_input(int n);
// Do not change anything above this line
Node* createNode(char dt){
Node* n=(Node*)malloc(sizeof(Node));
n->val=dt;
n->next=NULL;
return n;
}
int length(Node *head){
Node *tmp = head;
int counter = 0;
while(tmp != NULL){
counter += 1;
tmp = tmp->next;
}
return counter;
}
char GetNthfromStart(Node* head, int index)
{
Node* current = head;
int count = 0;
while (current != NULL) {
if (count == index)
return current->val;
count++;
current = current->next;
}
}
int isPalindrome(Node *head) {
int flag=0;
int len=length(head);
int i=0, j=len-1;//if this doesnt work do 0 and -1
while (i<j)
{
float average=(GetNthfromStart(head, i)+GetNthfromStart(head,j)-192)/2;
if(average!=(27/2)){
flag=1;
break;
}
i++;
j--;
}
if (flag==1)
{
return 0;
}
else return 1;
// write code here
}
Node* take_input(int n){
Node *head=NULL,*tail=NULL,*pt;
char ch;
for(int i=0;i<n;i++){
scanf("%c",&ch);
pt=createNode(ch);
if(head==NULL){
tail=pt;
head=tail;
}
else{
tail->next=pt;
tail=pt;
}
}
return head;
// Write code to take input here, do not change the return type.
}
// Do not change anything below this line
int main(){
int n;
scanf("%d\n",&n);
Node* head=take_input(n);
if(isPalindrome(head)) printf("Special String\n");
else printf("Not a special string\n");
}