Peter and Train
Peter and Train
(Deemed to be University)
ID NUMBER NAME
N. SREE RAM
Associate Professor
KL UNIVERSITY
Green fields, Vaddeswaram – 522 502
Guntur Dt., AP, India.
DEPARTMENT OF BASIC ENGINEERING SCIENCES
CERTIFICATE
Names: Regd.No:
1 Introduction 1
4 Flow Diagram 10
5 Algorithm Implementation 11
6 Implementation 12
8 Conclusion 14
1.INTRODUCTION
#include <(header_file_name).h>
int main()
{}
int main()
int a;
3. Body: Body of a function in C program, refers to the operations that are
performed in the functions. It can be anything like manipulations, searching,
sorting, printing, etc.
Example:
int main()
{
int a;
printf("%d", a);
2. Return Statement: The last part in any C program is the return statement.
The return statement refers to the returning of the values from a function.
This return statement and return value depend upon the return type of the
function. For example, if the return type is void, then there will be no return
statement. In any other case, there will be a return statement and the return
value will be of the type of the specified return type.
Example:
int main()
int a;
printf("%d", a);
return 0;
}
#include<stdio.h>In a C program, all lines that start with # areprocessed
by pre processor which is a program invoked by the compiler. In a very
basic term, pre processor takes a C program and produces another C
program. The produced program has no lines starting with #, all such lines
are processed by the pre processor. In the above example, pre processor
copies the pre processed code of stdio.h to our file. The .h files are called
header files in C. These header files generally contain declaration of
functions. We need stdio.h for the function printf() used in the program.
[ return 0; ] The return statement returns the value from main(). The
returned value may be used by operating system to know termination
status of your program. The value 0 typically means successful
termination.
AIM
They give you the list of the flags' colors 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 colors. The same letter stands for the same color, different
letters — for different colors.
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' colors 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 second line contains the sequence, written by Peter during the first period
of wakefulness. 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:
«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.
2.1. ADVANTAGES AND DISADVANTAGES
ADVANTAGES:
• Compilation creates unique strings. At compile time, strings are resolved
as far as possible. This includes applying the concatenation operator and
converting other literals to strings. Compilers differ in their ability to
achieve this resolution. You can always check your compiler (e.g., by
decompiling some statements involving concatenation) and change it if
needed.
• Because String objects are immutable, a substring operation doesn’t need
to copy the entire underlying sequence of characters. Instead, a substring can
use the same char array as the original string and simply refer to a different
start point and endpoint in the char array. This means that substring
operations are efficient, being both fast and conserving of memory; the extra
object is just a wrapper on the same underlying char array with different
pointers into that array.
DISADVANTAGES:
1. Not being able to subclass String means that it is not possible to add
behavior to String for your own needs.
2. The previous point means that all access must be through the restricted
set of currently available String methods, imposing extra overhead.
3. The only way to increase the number of methods allowing efficient
manipulation of String characters is to copy the characters into your own
array and manipulate them directly, in which case String is imposing an
extra step and extra objects you may not need.
4. char arrays are faster to process directly.
5. The tight coupling with String Buffer can lead to unexpectedly high
memory usage. When String Buffer .to String( ) creates a String, the current
underlying array holds the string, regardless of the size of the array (i.e., the
capacity of the String Buffer). For example, a String Buffer with a capacity
of 10,000 characters can build a string of 10 characters. However, that 10-
character String continues to use a 10,000-char array to store the 10
characters. If the String Buffer is now reused to create another 10-character
string, the String Buffer first creates a new internal 10,000-char array to
build the string with; then the new String also uses that 10,000-char array to
store the 10 characters. Obviously, this process can continue indefinitely,
using vast amounts of memory were not expected.
By using linked list we can able to reduce the time complexity along with
some data structures concepts
Another, probably more useful, function for windows would be the ability
for users to easily merge them so that two images or columns of text can be
joined just by moving the windows to the appropriate locations and issuing
simple mouse or keyboard commands. Likewise, it would be useful if users
had simple techniques for cutting windows (and their contents) into multiple
windows.
3. SYSTEM REQUIREMENTS
SOFTWARE REQUIREMENTS:
HARDWARE REQUIREMENTS:
The hardware requirements that map towards the software are as follows:
RAM : 8GB
STEP – 1: Start
If (strstr(ch+strlen(s1), s2))
Flag 1=1
Flag2=1
Print “both”
Print “forward”
Print “backward”
Print “fantasy”
STEP – 8: stop
6.Implementation
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int main()
{
char s[105], r[105];
int i,j,k;
char s1[100], s2[100],*ch;
int flag1=0, flag2=0;
scanf("%s%s%s", s,s1,s2);
k=0;
for(i=strlen(s)-1; i>=0; i--)
r[k++] = s[i];
r[k]='\0';
if(strstr(s ,s1))
{
ch=strstr(s, s1);
if(strstr((ch+strlen(s1)), s2))
flag1=1;
}
if(strstr(r, s1))
{
ch=strstr(r, s1);
if(strstr((ch+strlen(s1)), s2))
flag2=1;
}
if(flag1==1&&flag2==1) printf("both\n");
else if(flag1==1&&flag2==0) printf("forward\n");
else if(flag1==0&&flag2==1) printf("backward\n");
else if(flag1==0&&flag2==0) printf("fantasy\n");
return 0;
}
4. INTEGRATION AND SYSTEM TESTING
OUTPUTS
Screen Shots:
5. CONCLUS
8. CONCLUSION