0% found this document useful (0 votes)
3 views

Day 5

The document outlines a series of programming exercises focused on string manipulation for final year placement training. It includes tasks of varying difficulty, such as counting characters, reversing strings, checking for palindromes, and sorting string arrays. Each exercise provides input and output examples to guide learners in implementing solutions.

Uploaded by

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

Day 5

The document outlines a series of programming exercises focused on string manipulation for final year placement training. It includes tasks of varying difficulty, such as counting characters, reversing strings, checking for palindromes, and sorting string arrays. Each exercise provides input and output examples to guide learners in implementing solutions.

Uploaded by

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

Internal Placement Training

Placement Training for Final Years


Programming Questions

Day 5: Strings
Level: Easy
1. Write a program to input a string and print it.

Input:
Enter the string: Welcome to Internal Programming Training
Output:
The string entered is “Welcome to Internal Programming Training”

2. Write a program to find the length of a string using library functions.

Input:
Enter the string: Placement
Output:
The word “Placement” has 9 characters.

3. Write a program to separate individual characters from a string.

Input:
Enter the string: Training
Output:
The characters in the given string are: T, r, a, i, n, i, n, g

4. Write a program to copy one string to another string.

Input:

1|Page
Internal Placement Training

Enter the string: company


Output:
Original String – company
Copied string – company

5. Write a program to count the total number of vowels or consonants in a string.

Input:

2|Page
Internal Placement Training

Enter the string: Placement


Output:
There are 3 vowels and 6 consonants in the string “Placement”.

6. Write a program to find the maximum number of occurring characters in a string.

Input:
Enter the string: malayalam
Output:
„a‟ is the character the occurs more number of times in the given string “malayalam”.

7. Write a program to print individual characters of a string in reverse order.

Input:
Enter the string: Placement
Output:
Original string – Placement
Reversed string – tnemecalP

8. Write a program to count the total number of words in a string.

Input:
Enter the string: Internal programming training for final years
Output:
Number of words - 6

9. Write a program to compare two strings using string library functions.

Input:
Enter the first string: Placement
Enter the second string: Placed
Output:
Both strings are not equal

3|Page
Internal Placement Training

10. Write a program to read a sentence and replace lowercase characters with uppercase
and vice versa.

Input:
Enter the string: Placement Training
Output:
Original string – Placement Training
Toggled string – pLACEMENT tRAINING

11. Check if the given string is palindrome.

Input:
Enter the string: rotator
Output:
rotator is a palindrome

Level: Medium
12. Write a program in C to find the length of a string without using library functions.

Input:
Enter the string: Placement
Output:
The word “Placement” has 9 characters.

13. Write a C program to sort a string array in ascending order.

Input:
Enter the limit: 3
Enter the string:
python
c
java
Output:

4|Page
Internal Placement Training

Before Sorting – [python, c, java]


After Sorting – [c, java, python]

14. Write a program in C to extract a substring from a given string.

Input:
Enter the string: This is five days placement training
Enter the position to start extraction: 8
Enter the length of the substring: 4
Output:
The extracted substring is “five”

15. Write a C program to check whether a substring is present in a string.

Input:
Enter the string: training
Enter the substring: rain
Output:
“rain” is present in “training”

Input:
Enter the string: Residential Placement Training
Enter the substring: Placement
Output:
“Placement” is present in “Residential Placement Training”

16. Write a program in C to count the total number of alphabets, digits and special
characters in a string.

Input:
Enter the string: alice123wonder#land24
Output:
Number of alphabets – 14
Number of digits – 5

5|Page
Internal Placement Training

Number of special characters – 1

17. Write a program in C to compare two strings without using string library functions.

Input:
Enter the first string: Placement
Enter the second string: Placed
Output:
Both strings are not equal

18. Write a program in C to find the number of times a given word 'the' appears in
the given string.

Input:
Enter the string: This is the sample test case for the given program
Output:
Number of times „the‟ appears - 2

19. Write a program in C to find the largest and smallest words in a string.

Input:
Enter the string: Nokia launches a new mobile
Output:
Largest word – launches
Smallest word - a

20. Write a program in C to replace the spaces in a string with a specific character.

Input:
Enter the string: I enjoy watching comedy movies
Enter the special character to be replaced: @
Output:
Original string - I enjoy watching comedy movies
Altered string – I@enjoy@watching@comedy@movies

6|Page
Internal Placement Training

21. Write a C program to count each character in a given string.

Input:
Enter the string: have a cup of tea
Output:
Frequency table
h 1
a 3
v 1
e 2
c 1
u 1
p 1
o 1
f 1
t 1

22. Remove the vowels from the given input string.

Input:
Enter the string: placement
Output:
Original string: placement
Altered string: plcmnt

Level: Hard

23. Get two string array such that one contains the names with initial and another array
contains the family names. Match and Replace the initial with the family name such
that family name appears at the end. (Assume that the initials are unique).

For example,
Input:

7|Page
Internal Placement Training

[R.Smith, H.Mathew, L.George, W.Davis]


[Lewis, White, Hughes, Robert]
Output:
[Smith Robert, Mathew Hughes, George Lewis, Davis White]

24. Given a non-palindrome string check whether it can be converted to a palindrome


string.

For example,
Input:
Java
Output:
No, it is not possible :(
Input:
off
Output:
Yes, it is possible :)

25. Given a string containing numbers and other characters, find the sum of all the
numbers in the string.

Example 1:
Input: "abc12def34"
Output: 46
Example 2:
Input: "1a2b3c"
Output: 6

26. Problem Description : [Accenture]


The Binary number system only uses two digits, 0 and 1 and number system can be
called binary string. You are required to implement the following function:
int OperationsBinaryString(char* str);
The function accepts a string str as its argument. The string str consists of binary
digits eparated with an alphabet as follows:

8|Page
Internal Placement Training

– A denotes AND operation


– B denotes OR operation
– C denotes XOR Operation
You are required to calculate the result of the string str, scanning the string to right
taking one opearation at a time, and return the same.
Note:
No order of priorities of operations is required
Length of str is odd
If str is NULL or None (in case of Python), return -1

Input:
str: 1C0C1C1A0B1
Output:
1
Explanation:
The alphabets in str when expanded becomes “1 XOR 0 XOR 1 XOR 1 AND 0 OR
1”, result of the expression becomes 1, hence 1 is returned.
Sample Input:
0C1A1B1C1C1B0A0
Output:
0

27. Consider a string, S, that is a series of characters, each followed by its frequency as an
integer. The string is not compressed correctly, so there may be multiple occurrences
of the same character. A properly compressed string will consist of one instance of
each character in alphabetical order followed by the total count of that character
within the string. [IBM]
28. Write a program that will take one string as input. The program will then remove
vowels a, e, i, o, and u (in lower or upper case ) from the string. If there are two or
more vowels that occur together then the program shall ignore all of those vowels.
[Zoho]

Example 1
Input: Cat

9|Page
Internal Placement Training

Output: Ct
Example 2
Input: Compuuter
Output: Cmpuutr

29. Write a program that will take a string as input. The program will then determine
whether each left parenthesis „(‟ has a matching right parenthesis „)‟ and also all the
„)‟ has a consecutive „(„. If so, the program will print 0 else the program will print 1.
[Zoho]

Example 1
Input: HELLO AND (WELCOME (TO THE) TCEA (CONTEST)TODAY)IS
(SATURDAY())
Output: 0
Example 2
Input: (9*(7-2)*(1*5)
Output: 0

30. Write a program that receives a word A and some texts as input. You need to output
the texts (without modifying them) in the ascending order of the number of
occurrences of the word A in the texts. The input is as follows: an integer M(between
1 and 100, inclusive), followed by the word A in the next line, and some text in each
of the M next lines. [Capgemini]
Note: The texts and the word A contain only lowercase Latin letters (a,b,c…,z) and
blank spaces (“ ”). The maximum size of the texts and the word A is 100 Characters.
Every text has a different number of occurrences of the word A.
Note 2:you must print one text per line without modifying the texts.

Example 1
Input: 2
Java
I hate java
Python is a good programming language
Output: Python is a good programming language

10 | P a g e
Internal Placement Training

I hate java
Example 2
Input: 3
python
I like to code in python
python is named after a show name monty python and not after the snake
python
I think python is good i think python is important than php
Output: i like to code in python
i think python is good i think python is important than php
python is named after a show name monty python and not after the snake
python

31. A furnishing company is manufacturing a new collection of curtains. The curtains are
of two colors aqua(a) and black (b). The curtains color is represented as a string(str)
consisting of a‟s and b‟s of length N. Then, they are packed (substring) into L
number of curtains in each box. The box with the maximum number of „aqua‟ (a)
color curtains is labeled. The task here is to find the number of „aqua‟ color curtains
in the labeled box. [TCS]
Note :
If „L‟ is not a multiple of N, the remaining number of curtains should be considered
as a substring too. In simple words, after dividing the curtains in sets of „L‟, any
curtains left will be another set(refer example 1)

Example 1:
Input :
bbbaaababa -> Value of str

3 -> Value of L
Output:
3 -> Maximum number of a‟s
Explanation:
From the input given above.
Dividing the string into sets of 3 characters each

11 | P a g e
Internal Placement Training

Set 1: {b,b,b}
Set 2: {a,a,a}
Set 3: {b,a,b}
Set 4: {a} -> leftover characters also as taken as another set
Among all the sets, Set 2 has more number of a‟s. The number of a‟s in set 2 is 3.
Hence, the output is 3.
Example 2:
Input :
abbbaabbb -> Value of str
5 -> Value of L
Output:
2 -> Maximum number of a‟s
Explanation:
From the input given above,
Dividing the string into sets of 5 characters each.
Set 1: {a,b,b,b,b}
Set 2: {a,a,b,b,b}
Among both the sets, set 2 has more number of a‟s. The number of a‟s in set 2 is 2.
Hence, the output is 2.
Constraints:
1<=L<=10
1<=N<=50
The input format for testing
The candidate has to write the code to accept two inputs separated by a new line.
First input- Accept string that contains character a and b only
Second input- Accept value for N(Positive integer number)
The output format for testing
The output should be a positive integer number of print the message(if any) given in
the problem statement.(Check the output in Example 1, Example 2).

12 | P a g e

You might also like