Pps Case Study Document
Pps Case Study Document
Bachelor of Technology
in
by
PALADUGUASRITHA (226Y1A66E2)
PALLA SRIJA (226Y1A66E3)
PARIKIRALA VYSHNAVI (226Y1A66E4)
Assistant Professor
2022-2023
DEPARTMENT OF COMPUTER SCIENCE ENGINEERIN (AIML)
CERTIFICATE
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;
return s;
}
PROBLEM SUBMISSION SCREENSHOT