Professional Documents
Culture Documents
On
SUBMITTED BY:
2100031810 B.PRANAVI
Mr.B.ASHOK KUMAR
Assistance Professor
KL UNIVERSITY
Green fields, Vaddeswaram – 522 502
Guntur Dt., AP, India.
1
DEPARTMENT OF BASIC ENGINEERING SCIENCES
CERTIFICATE
2
ACKNOWLEDGEMENTS
I express the sincere gratitude to our director Dr. A Jagadeesh for his
administration towards our academic growth.
Name: <NAME>
3
ABSTRACT
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
5 Implementation 13,14
6 Outputs/ScreenShots 15,16
7 Conclusion 17
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.
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 of2-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 strine ill the specified main string and
returns the pointer to the first occurrence of the given string.
7
char *strstr(const char *str, const char*searchstrlng)
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 Xp or later.
HARDWARE REQUIREMENTS:
The hardware requirements that map towards the software are as follows:
RAM :8 GB
Processor : i5
9
CLASS DIAGRAM
10
11
ALGORITHM
Step 1: Start
Declare j
Step 3: 3.1:for(k=0;k<t;k+ +)
12
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)
ifp)
C=C+1
end
B[k]=c
end
Step 4: 4.1for(j=0;j<t:j++)
Begin
4.2: If b[j]=0||b[]%2==0)
4.2.1:Print "Tracy"
Else
4.2.1:Print 'Teddy"
End
Step 5: Stop.
IMPLEMENTATION
#include<stdio.h>
#include<string.h>
int main()
13
{
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++)
if(b[j]=0||b[j]%2==0)
printf("Tracy\n");
else
14
printf("Teddy\n");
return 0;
OUTPUTS
Screen Shots:
15
16
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
17