Beruflich Dokumente
Kultur Dokumente
On
SUBMITTED BY:
Xxxxxxxxxxx
Xxxxxxxxxx
xxxxxxx
Assistant Professor
1
CERTIFICATE
xxxxxx xxxxx
ACKNOWLEDGEMENTS
We express the sincere gratitude to our Director XXXX for his administration
towards our academic growth.
2
We express sincere gratitude to our Coordinator XXXXXy and HOD-BES XXXXfor
her leadership and constant motivation provided in successful completion of our academic
semester. I record it as my privilege to deeply thank for providing us the efficient faculty
and facilities to make our ideas into reality.
We express my sincere thanks to our project supervisor XXXX for her novel
association of ideas, encouragement, appreciation and intellectual zeal which motivated us
to venture this project successfully.
ABSTRACT
Peter likes to travel by train. He likes it so much that on the train he falls asleep.Once in
summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he
woke up, started to look through the window and noticed that every railway station has a
flag of a particular colour.
The boy started to memorize the order of the flags' colours that he had seen. But soon he
fell asleep again. Unfortunately, he didn't sleep long, he woke up and went on memorizing
the colours. Then he fell asleep again, and that time he slept till the end of the journey.
At the station he told his parents about what he was doing, and wrote two sequences of the
colours that he had seen before and after his sleep, respectively.
3
Peter's parents know that their son likes to fantasize. They give you the list of the flags'
colours at the stations that the train passes sequentially on the way from A to B, and ask
you to find out if Peter could see those sequences on the way from A to B, or from B to A.
Remember, please, that Peter had two periods of wakefulness.
Peter's parents put lowercase Latin letters for colours. The same letter stands for the same
colour, different letters — for different colours.
Input
The input data contains three lines. The first line contains a non-empty string, whose length
does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the
stations on the way from A to B. On the way from B to A the train passes the same stations,
but in reverse order.. The third line contains the sequence, written during the second period
of wakefulness. Both sequences are non-empty, consist of lowercase Latin letters, and the
length of each does not exceed 100 letters. Each of the sequences is written in
chronological order.
Output
Output one of the four words without inverted commas:
«forward» — if Peter could see such sequences only on the way from A to B;
«backward» — if Peter could see such sequences on the way from B to A;
«both» — if Peter could see such sequences both on the way from A to B, and on the
way from B to A;
«fantasy» — if Peter could not see such sequences.
INDEX
S.NO TITLE PAGE NO
1 Introduction 6
4
2.2 Future Implementation 7
4 Implementation 10-12
7 Conclusion 14
INTRODUCTION
The project “Train and Peter” is extensively based on the concept of strings.
It also uses for loop and flag variables
The project is to find the order of stations which Peter memorized during his period
of wakefulness
The input of the program is order of stations from destination A to destination B
The next Two inputs are memorizing order of stations which Peter did during his
two periods of wakefulness respectively
5
AIM
The project is to find the order of stations which Peter memorized during his period
of wakefulness.
The elaboration can be done using an example:
Output:-
6
Both – It is the output as “aca” , ”aa” are sub strings of the main string in both
forward and backward ways.
Output should be “Forward” when the substring condition satisfies from left to
right
Output should be “Backward” when the substring condition satisfies from right to
left.
Output should be “Fantasy” when none of the above conditions are True
SYSTEM REQUIREMENTS
SOFTWARE REQUIREMENTS:
The major software requirements of the project are as follows:
Language : Turbo-C
Operating system: Windows Xp or later.
HARDWARE REQUIREMENTS:
The hardware requirements that map towards the software are as follows:
7
RAM :4GB & Above
ALGORITHM
1.Start
2.Initialize four flag variables with 0
3.Read strings as input
Output should be “Forward” when the substring condition satisfies from left to
right
Output should be “Backward” when the substring condition satisfies from right to
left.
Output should be “Fantasy” when none of the above conditions are True
5. Stop
8
IMPLEMENTATION
#include<stdio.h>
#include<string.h>
int main()
char T[100020],A[120],B[120];
gets(T);
9
gets(A);
gets(B);
x=strlen(T);
y=strlen(A);
z=strlen(B);
for(i=0;i<x;i++)
k = i;
for(j=0;j<y&&flag==0&&T[k]!='\0';j++,k++)
if(A[j] != T[k])
flag = 0;
break;
if(j == y - 1)
flag = 1;
};
k = i +y;
if(B[j] != T[k])
flag2 = 0;
break;
if(j == z - 1)
10
flag2 = 1;
k++;
k = i;
if(A[j] != T[k])
flag3 = 0;
break;
if(j ==y- 1)
flag3 = 1;
k--;
k = i -y;
if(B[j] != T[k])
flag4 = 0;
break;
if(j == z- 1)
11
{
flag4 = 1;
k--;
printf("both");
printf("forward");
printf("backward");
else
12
CONCLUSION
Thus we can Conclude that the order of Memorization of stations by peter can be
easily calculated using the concepts of Loops and Strings
13
14