You are on page 1of 18

K L UNIVERSITY

FRESHMAN ENGINEERING DEPARTMENT


A Project Based Lab Report

On

TEDDY AND TRACY

SUBMITTED BY:

I.D NUMBER NAME

190030545 G.sai sri harsha

190030570 G.manas kiran

190030590 P. Hanu Shanmukha Priya

190030598 I.vivek vardhan

UNDER THE ESTEEMED GUIDANCE OF

S.shiva kumar

ASSISTANT PROFESSOR

KL UNIVERSITY
Green fields, Vaddeswaram – 522 502
Guntur Dt., AP, India.

1
DEPARTMENT OF BASIC ENGINEERING SCIENCES

CERTIFICATE

This is to certify that the project based laboratory report entitled


“<Teddy and Tracy>” submitted by Mr./Ms. G.sai sri harsha,G.manaskiran,
P.shanmukhaPriya,I.vivekVardhanbearingRegd.No.190030545,190030570,19
0030590,190030598 to the Department of Basic Engineering Sciences, KL
University in partial fulfillment of the requirements for the completion of a
project based Laboratory in “Technical Skills-I(Coding)”course in I B Tech I
Semester, is a bonafide record of the work carried out by him/her under my
supervision during the academic year 2019 – 2020.

PROJECT SUPERVISOR HEAD OF THE DEPARTMENT

Mr S.shiva kumar Dr. D.HARITHA

2
ACKNOWLEDGEMENTS
It is great pleasure for me to express my gratitude to our honorable
President Sri. Koneru Satyanarayana, for giving the opportunity and platform
with facilities in accomplishing the project based laboratory report.

I express the sincere gratitude to our Director Dr. A. Jagdeesh for his
administration towards our academic growth.

I express sincere gratitude to our Coordinator and HOD-BES Dr. D.Haritha


for 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.

I express my sincere thanks to our project supervisor Mr S.shiva kumar


for his/her novel association of ideas, encouragement, appreciation and
intellectual zeal which motivated us to venture this project successfully.

Finally, it is pleased to acknowledge the indebtedness to all those who


devoted themselves directly or indirectly to make this project report success.

3
ABSTRACT
Teddy and Tracy
Teddy and Tracy like to play a game based on strings. The game is as follows. Initially, Tracy
writes a long random string on a whiteboard. Then, each player starting with Teddy makes
turn alternately. Each turn, the player must erase a contiguous substring that exists in the
dictionary.

The dictionary consists of N words.

Of course, the player that can't erase any substring in his turn loses the game, and the other
player is declared the winner.

Note that after a substring R is erased, the remaining substring becomes separated, i.e. they
cannot erase a word that occurs partially to the left of R and partially to the right of R.
Determine the winner of the game, assuming that both players play optimally.

Input
The first line contains a single integer T, the number of test cases. T test cases follow. The
first line of each test case contains a string S, the string Tracy writes on the whiteboard. The
next line contains a single integer N. N lines follow. The i-th line contains a single string wi,
the i-th word in the dictionary.

Output
For each test case, output a single line containing the name of the winner of the game.

4
INDEX
S.NO TITLE PAGE NO
1 Introduction 6-7

2 Aim of the Project 8

2.1 Advantages & Disadvantages 8

2.2 Future Implementation 8

3 Software & Hardware Details 9

4 Data Flow Diagram 10-11

5 Algorithm for each module 12-13

6 Implementation 14-15

7 Integration and System Testing 16-17

8 Conclusion 18

5
INTRODUCTION
Teddy and Tracy like to play a game based on strings. The game is as follows. Initially, Tracy
writes a long random string on a whiteboard. Then, each player starting with Teddy makes
turn alternately. Each turn, the player must erase a contiguous substring that exists in the
dictionary.

The dictionary consists of N words.

Of course, the player that can't erase any substring in his turn loses the game, and the other
player is declared the winner.

Note that after a substring R is erased, the remaining substring becomes separated, i.e. they
cannot erase a word that occurs partially to the left of R and partially to the right of R.
Determine the winner of the game, assuming that both players play optimally.

In this projects we have used the concepts of strings , loops,arrays, conditional statements
like if else and specially we have used a string STRSTR().

Strings in C
Strings are defined as an array of characters. The difference between a character array and
a string is the string is terminated with a special character ‘\0’.

Declaration of strings: Declaring a string is as simple as declaring a one dimensional array.


Below is the basic syntax for declaring a string.
Syntax:
char str_name[size];
In the above syntax str_name is any name given to the string variable and size is used define
the length of the string, i.e the number of characters strings will store. Please keep in mind
that there is an extra terminating character which is the Null character (‘\0’) used to indicate
termination of string which differs strings from normal character arrays.

6
This program takes string and its substring as input and removes the substring from the
string.

 Take a string and its substring as input.

 Put each word of the input string into the rows of 2-D array.

 Search for the substring in the rows of 2-D array.

 When the substring is got, then override the current row with next row and so on
upto the last row.

You need to often manipulate strings according to the need of a problem. Most, if not all, of
the time string manipulation can be done manually but, this makes programming complex
and large.
To solve this, C supports a large number of string handling functions in the standard library
String.h.

Few commonly used string handling functions are strlen(),strcpy(),strcat(),strcmp(),etc….

Strstr() function searches the given string in the specified main string and
returns the pointer to the first occurrence of the given string.

Therefore it is necessary to include string header file to use standard C string library
function strstr( ).

C strstr() function declaration


char *strstr(const char *str, const char *searchString)

str – The string to be searched.


searchString – The string that we need to search in string str

7
AIM OF PROJECT:

It is based on the strings and the substring are erased from the given string by the
players based on words in dictionary.

Advantages:-
C string are very fast in processing because it stored in array and we utilize array
indexing to accessing part of string or whole.
Compile-time allocation and determination of size.

Disadvantages:-

Fixed size.

Primitive C arrays do not track their own size, so programmer has to be


careful about boundaries
While there are some library functions that work with C-strings, programmer
still has to be careful to make correct calls. These library functions do not
protect boundaries either!
Less intuitive notation for such usage (library features)

Future enhancements:-
 We can write the program for finding the substring from the given string without
using library function i.e. strstr().
 We can build many programs with stings and arrays by using different concepts as
like of this project.

8
SYSTEM REQUIREMENTS

 SOFTWARE REQUIREMENTS:
The major software requirements of the project are as follows:
Language : Turbo-C
Operating system: Windows 10 or later.

 HARDWARE REQUIREMENTS:

The hardware requirements that map towards the software are as follows:

RAM : 8GB

Processor : i5

9
FLOW CHART DIAGRAM

10
11
ALGORITHM

Step 1: Start

Step 2: Read t,b[100],k

Declare j

Step 3: 3.1:for(k=0;k<t;k++)

Begin

3.2:Read s[100],s,n

Declare n,i,c=0

3.3:For(i=0;i<n;i++)

Begin

3.4:Read a[100],*p

3.5:p =strstr(s,a)

if(p)

c=c+1

end

b[k]=c

end

Step 4: 4.1:for(j=0;j<t;j++)

Begin

4.2: If(b[j]==0||b[j]%2==0)

4.2.1:Print “Tracy”

Else

4.2.1:Print “Teddy”

12
End

Step 5: Stop.

13
IMPLEMENTATION

#include<stdio.h>

#include<string.h>

int main()

int t,k,b[100],j;

scanf("%d",&t);

for(k=0;k<t;k++)

char s[100];

int n,i,c=0;

scanf("%s",s);

scanf("%d",&n);

for(i=0;i<n;i++)

char a[100],*p;

scanf("%s",a);

p=strstr(s,a);

if(p)

c++;

b[k]=c;

for(j=0;j<t;j++)

14
if(b[j]=0||b[j]%2==0)

printf("Tracy\n");

else

printf("Teddy\n");

return 0;

15
INTEGRATION AND SYSTEM TESTING
OUTPUTS
Screen Shots:

16
17
CONCLUSION
By this project we under stood the concepts of strings and know how to how to get

substring from the given string and got all the several string library functions used to

manipulate strings and understood and finished the project and getting outputs for the

given inputs.

18

You might also like