ACP Lab Session 3 Questions
ACP Lab Session 3 Questions
&
ADVANCED C PROGRAMMING
Lab Session - 3
S.
Questions
No
1 Chef invented a modified wordle. There is a hidden word S and a guess word T, both of length 5.
Chef defines a string M to determine the correctness of the guess word. For the
ith index:
If the guess at the ith index is correct, the ith character of M is ith character.
If the guess at the ith index is wrong, the ith character of M is the ith character with lower ASCII
value.
Given the hidden word S and guess T, determine string M. (USE POINTERS FOR ACCESSING
CHARACTER ARRAYS)
Input Format:
First line will contain T, number of test cases. Then the test cases follow.
Each test case contains of two lines of input.
First line contains the string S - the hidden word.
Second line contains the string T - the guess word.
Output Format:
For each test case, print the value of string M.
Constraints:
1≤T≤1000; ∣S∣=∣T∣=5
S,T contain uppercase English alphabets only.
Input Output
3 ABCBA
ABCDE RINGD
EDCBA STANT
ROUND
RINGS
START
STUNT
Explanation:
Test Case 1: Given string S=ABCDE and T=EDCBA. The string M is:
Comparing the first indices, A≠E, thus, M [0]=A.
Comparing the second indices, B≠D, thus, M [1]=B.
Comparing the third indices, C=C thus, M [4]=C.
Comparing the fourth indices, D≠B, thus, M [5]=B.
Comparing the fifth indices, E≠A, thus, M [6]=A.
2 You have initially a string of N characters, denoted by A1,A2...AN. You have to print the size of the
largest subsequence of string A such that all the characters in that subsequence are distinct ie. no two
characters in that subsequence should be same.
A subsequence of string A is a sequence that can be derived from A by deleting some elements and
without changing the order of the remaining elements.
(USE POINTERS FOR ACCESSING CHARACTER ARRAYS)
Input
First line contains T, number of testcases. Each testcase consists of a single string in one line. Each
character of the string will be a small alphabet(ie. 'a' to 'z').
Output
For each testcase, print the required answer in one line.
Constraints
1 ≤ T ≤ 10
Subtask 1 (20 points):1 ≤ N ≤ 10
Subtask 2 (80 points):1 ≤ N ≤ 105
Input Output
2 3
abc 2
aba
Explanation:
For first testcase, the whole string is a subsequence which has all distinct characters.
In second testcase, we can delete last or first 'a' to get the required subsequence.
3 Chef recently visited ShareChat Cafe and was highly impressed by the food. Being a food enthusiast,
he decided to enquire about the ingredients of each dish.
There are N dishes represented by strings S1,S2,…,SN. Each ingredient used for making dishes in
ShareChat Cafe is represented by a lowercase English letter. For each valid i, the ingredients used to
make dish i correspond to characters in the string Si (note that ingredients may be used multiple times).
A special ingredient is an ingredient which is present in each dish at least once.
Chef wants to know the number of special ingredients in ShareChat Cafe. Since Chef is too busy with
work, can you help him? (USE POINTERS FOR ACCESSING CHARACTER ARRAYS)
Input
The first line of the input contains a single integer T denoting the number of test cases. The
description of T test cases follows.
The first line of each test case contains a single integer N.
N lines follow. For each i (1≤1≤i≤N), the i-th of these lines contains a single string Si.
Output: For each test case, print a single line containing one integer ― the number of special
ingredients in the dishes.
Constraints:
1≤T≤1,000
1≤N≤1,000
1≤∣Si∣≤200 for each valid i
S1,S2,…,SN contain only lowercase English letters
Input Output
2 2
3 0
abcaa
bcbd
bgc
3
quick
brown
fox