0% found this document useful (0 votes)
9 views7 pages

Pps Case Study Document

Uploaded by

Palla Srija
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)
9 views7 pages

Pps Case Study Document

Uploaded by

Palla Srija
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/ 7

A

CASE STUDY REPORT


On

REVERSE WORDS IN A STRING


Submitted to

Jawaharlal Nehru Technological University, Hyderabad


in partial fulfillment of the requirements for the award of Degree of

Bachelor of Technology
in

Computer Science & Engineering (Artificial intelligence and machine learning)

by
PALADUGUASRITHA (226Y1A66E2)
PALLA SRIJA (226Y1A66E3)
PARIKIRALA VYSHNAVI (226Y1A66E4)

Under the Guidance


Of
Mr.B. PRASHANTH

Assistant Professor

Department of Computer Science & Engineering ( AIML)

2022-2023
DEPARTMENT OF COMPUTER SCIENCE ENGINEERIN (AIML)

CERTIFICATE

This is to certify that the Case Study entitled “REVERSE WORDS IN A


SRING” is submitted by PALADUGU ASRITHA (226Y1A66E2) , PALLA
SRIJA (226Y1A66E3), PARIKIRALA VYSHNAVI (226Y1A6679), in the
partial fulfillment of requirement for the award of degree of Bachelor of Technology
in Computer Science and Engineering (AIML) during academic year 2022-23.

Mr.B.PRASHANTH Dr.E.SUDARSHAN
Faculty Mentor Head of the Department
INDEX

CONTENT PAGE NO

1. PROBLEM DESCRIPTION 4

2. PROBLEM ANALYSIS 5

3. PROBLEM SOULTION 6
4.PROBLEM SUBMISSION SCREENSHOT 7
PROBLEM DESCRIPTION

PROBLEM:
Given an input string s, reverse the order of the words.
DEFINITION:
A word is defined as a sequence of non-space characters. The
words in string s will be separated by at least one space.
EXPLAINATION:
 Return a string of the words in reverse order concatenated by a single
space.
 Note that string S may contain leading or trailing spaces or multiple
spaces between two words. The returned string should only have a
single space separating the words. Do not include any extra spaces.
EXAMPLES:

Example 1:
Input: s = "the sky is blue"
Output: "blue is sky the"

Example 2:
Input: s = " hello world "
Output: "world hello"
Explanation: Your reversed string should not contain leading or trailing
spaces.

Example 3:
Input: s = "a good example"
Output: "example good a"
Explanation: You need to reduce multiple spaces between two words to a
single space in the reversed string.

CONSTRAINTS:
1 <= s.length <= 104
s contains English letters (upper-case and lower-case), digits, and spaces ' '.
There is at least one word
PROBLEM ANALYSIS
we can execute the program using arrays and while loop to show our target
output correctly.
PROBLEM SOLUTION
char* reverse_word (char* s, int j, int i)
{
char t;
while (j < i)
{
t = s[i];
s[i--] = s[j];
s[j++] = t;
}
return s;
}

char * reverseWords(char * s)
{

unsigned int i = 0;
unsigned int j = 0;
unsigned int x = 0;
char t;
while (s[i] != '\0')
{
if (s[i] == ' ')
{
i++;
continue;
}
j = i;
while (s[i] != ' ')
{
i++;
if (s[i] == '\0')
break;
}
s = reverse_word(s, j, i-1);
}

i = 0;
j = strlen(s) -1;
while ( i < j) {
t = s[i];
s[i++] = s[j];
s[j--] = t;
}

i = 0;
j = 0;

while (s[i] == ' ')


{
i++;
}
s = s+i;
i = 0;
x = strlen(s) -1;
while (s[x] == ' ')
x--;
s[++x] = '\0';
while (s[i] != '\0')
{
while (s[i] != '\0' && s[i] == ' ')
{
i++;
if (s[i] != ' ')
s[j++] = ' ';
}
while (s[i] != '\0' && s[i] != ' ')
{
s[j++] = s[i++];
}
if (s[i] == '\0')
s[j] = '\0';
}

return s;
}
PROBLEM SUBMISSION SCREENSHOT

You might also like