Professional Documents
Culture Documents
On
SUBMITTED BY:
S.shiva kumar
ASSISTANT PROFESSOR
KL UNIVERSITY
Green fields, Vaddeswaram – 522 502
Guntur Dt., AP, India.
1
DEPARTMENT OF BASIC ENGINEERING SCIENCES
CERTIFICATE
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.
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.
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
6 Implementation 14-15
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.
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’.
6
This program takes string and its substring as input and removes the substring from the
string.
Put each word of the input string into 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.
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( ).
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.
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
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