0% found this document useful (0 votes)
60 views14 pages

CTSD Project Documentation Template (1) - Extracted

The document describes a string game played by Teddy and Tracy. Initially, Tracy writes a random string on a whiteboard. Then, each player takes a turn trying to erase a contiguous substring from the string that exists in a dictionary of N words. If a player cannot erase a substring on their turn, they lose. The winner is determined by seeing which player goes last without losing a turn. The algorithm and implementation for determining the winner is described, assuming both players play optimally.

Uploaded by

vishnu Vardhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views14 pages

CTSD Project Documentation Template (1) - Extracted

The document describes a string game played by Teddy and Tracy. Initially, Tracy writes a random string on a whiteboard. Then, each player takes a turn trying to erase a contiguous substring from the string that exists in a dictionary of N words. If a player cannot erase a substring on their turn, they lose. The winner is determined by seeing which player goes last without losing a turn. The algorithm and implementation for determining the winner is described, assuming both players play optimally.

Uploaded by

vishnu Vardhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

ABSTRACT

Teddy and Tracy like to play a game based on strings. The game is as follows.
Initially, Tracy writes a Jong 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.
INDEX
S.NO TITLE PAGE NO

1 Introduction 1

2 Aim of the Project 2

2.1 Advantages & Disadvantages 2

2.2 Future Implementation 2

3 Software & Hardware Details 3

4 Algorithm 4

5 Flowchart 5

6 Implementation 8

7 Results and Screenshots 10

8 Conclusion 11
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 tum, the player must erase a
contiguous substring that exists in the dictionary. The dictionary consists of N
words. Of course, the playerthat 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 Rand 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 el>" 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 '
\O'. Oeclaratlon of atringa: Declaring a string Is as simple as declaring a one
dimensional array. Below is the basic syntax for declaring a string. Syntax: char
str_na~e[size); In the above syntax sir _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. Thl_s
program takes string and Its substring as input and removes the substn·ng f h
string. rom t e

► 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·0 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(l.strcat(),strcmp(),etc .... .., strstr() function searches the given
string in the specified main siring 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
AIM
It is based on the strings and the substring arc erased li'om the given string by
the players based on 'Nords in dictionary.

Advantages:-

1. C string are very fast In processing because it stored In array and we


utilize array indexing to accessing part of string or whole
2. 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 .i. While there are some library functions that work
with ( ·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:-
1. We can write the program for finding the substring from the given string
without using library function i.e. strstr().
2. We can build many programs with stings and arrays by using different
concepts as like of this project.
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 :8GB

Processor :I5 PROCESSOR 12TH GEN


ALGORITHM

Step 1:- Start.


Step 2:- Define d[50][50],s[100].
Step 3:- Read
t,i,j,k,n,l,g[50][50],temp[100],len[100],le,u,l=0,
Step 4:- for(i=0;i<len;i++)
Step 5:- if(a[i]!=b[i])
5.1:- return 0,return 1
Step 6:- while(t--)
6.1:- l=strlen(s)
6.2:- for(i=0;i<1;i++)
6.3:- len(i)=strlen(d[i])
6.4:- for(i=0;i<1;i++)
6.5:- g(i)(i)=0
Step 7:- for(le=1;le<=l;le++)
7.1:- for(i=0;i<(len-l);i++)
7.2:- j=i+le
7.3:- c++
Step 8:- for(k=0;k<n;k++)
8.1:- if(len[k]<=le)
8.2:- for(u=i;u<=cj-lrn[k];u++)
8.3:- if(match(s+u,d[k],len[k]))
8.4:- temp[g[i][u]^g[u+len[k]][j]]=c;
Step 9:- for(k=0;temp[k]==c;k++)
9.1:- g[i][j]=k;
Step 10:- Dispaly(!g[0][1])?"Tracy";"Teddy")
Step 11:- Stop.
FLOWCHART
IMPLEMENTATION
#include<stdio.h>

#include<string.h>

char d[50][50],s[100];
int t,i,j,k,n,l,g[50][50],temp[100],len[100],le,u,c=0;

int match(char a[],char b[],int len)

{
int i;
for(i=0;i<len;i++) if(a[i]!=b[i]) return 0;
return 1;
}
int main()

{
scanf("%d",&t);
while(t--)
{
scanf("%s",s);

l=strlen(s);

scanf("%d",&n);

for(i=0;i<n;i++) scanf("%s",d[i]),len[i]=strlen(d[i]);
for(i=0;i<l;i++)
g[i][i]=0;
for(le=1;le<=l;le++){

for(i=0;i<=(l-le);i++){
j=i+le;c++;

for(k=0;k<n;k++){
if(len[k]<=le){
for(u=i;u<=(j-len[k]);u++) if(match(s+u,d[k],len[k])){
temp[g[i][u]^g[u+len[k]][j]]=c;
}
}
}
for(k=0;temp[k]==c;k++); g[i][j]=k;
}
}
printf("%s\n",(!g[0][l])?"Tracy":"Teddy");
}
}
RESULTS AND SCREENSHOTS

OUTPUTS

Screen Shots:
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.

You might also like