Problem:-
You are given a string S and an integer Q. You are allowed to perform at most Q operations on the string. In one operation, you can change any vowel to it's next character (e.g., 'a'->'b', 'e'->'f', 'i'->'j', 'o'->'p', 'u'->'v'). Generate the lexicographically greatest string by performing at most Q operations on string S.
Note- Vowels in English alphabet are- 'a','e','i','o','u'.
Input Format:
First line contains an integer T denoting the number of test cases .
For each test case,in first line you will be given the string S and in second line an integer Q (maximum number of operations allowed).
Output Format:
For each test case , print the lexicographically greatest string that can be formed after applying at most Q operations on the given string.
Answer for each test case should come in a new line.
Constraints:
String will consist of only lowercase English alphabets.
Note- Vowels in English alphabet are- 'a','e','i','o','u'.
Input Format:
First line contains an integer T denoting the number of test cases .
For each test case,in first line you will be given the string S and in second line an integer Q (maximum number of operations allowed).
Output Format:
For each test case , print the lexicographically greatest string that can be formed after applying at most Q operations on the given string.
Answer for each test case should come in a new line.
Constraints:
String will consist of only lowercase English alphabets.
Explanation
For case 1:
We have string "abcde" and we are allowed to perform at max 3 operations, we can form lexicographically greatest string by applying the operation on first and last character of string by changing the string to "bbcdf",which is lexicographically greatest.
For Case 2:
We are not allowed to do any operations, so the answer will be the string itself.
We have string "abcde" and we are allowed to perform at max 3 operations, we can form lexicographically greatest string by applying the operation on first and last character of string by changing the string to "bbcdf",which is lexicographically greatest.
For Case 2:
We are not allowed to do any operations, so the answer will be the string itself.
Time Limit:1.0 sec(s) for each input file.
Memory Limit:256 MB
Source Limit:
solution:-
#include<stdio.h>
void main()
{
int t,q,k=1;
char s[100000];
scanf("%d",&t);
for(int i=1;i<=t;i++)
{
scanf("%s",s);
scanf("%d",&q);
for(int j=0;s[j];j++)
{
if(k>q)
break;
else
{
int x;
x=s[j];
if(s[j]=='a'||s[j]=='e'||s[j]=='i'||s[j]=='o'||s[j]=='u')
{
x=x+1;
s[j]=x;
k++;
}}
}
printf("%s\n",s);
k=1;
}
}
0 Comments