Question: PhonePe | OA | MSRIT | 2023 | Story Teller | Decode String | Birthday Conundrum | Reduce to Zero
3
Entering edit mode

Description

1. Story Teller

In Tarnasha movie, there is a kid named Ved who lives in Manali. He loves hearing stories from a story-teller who lives in their neighbourhood. The story-teller charges Y rupees for every story he tells and for every Z stories which
Ved can remember and summarize on a later day, he tells an additional story Ved can summarize a story only once and he never forgets a story We need to calculate the maximum number of stories which Ved can hear

 

Input 

  • The first line contains an integer T denoting the number of test cases to analyze
  • Each of next T lines contains three-spaces integers integers X,Y and Z where
    • X - Ved 's initial amount of money
    • Y - Story teller fees for a story
    • Z - the number of stories taht needs to be remebered and summarized for a free story

Output

  • For each test case print the total number of stories which Ved can hear on anew line

Constraints 

  • 1 <= T <= 1000
  • 2 <= X <= 105   
  • 1 <= Y <= X
  • 2 <= Z <= X
Sample Input
3 
 
10 2 5

12 4 4

6 2 2 


Sample Output

6

3

5

 

Explanation


spends his 10 rupees to hear 5 stories at a cost of Rs 2/story. He summarizes all of them to hear an additional story Total 6 Le spends his 12 rupees to hear 3 stories at a cost of Rs.4/story Total 3 spends his 6 rupees to hear 3 stories at a cost of Rs.2/story He then
arizes 2 of the stories and save one for later to hear his 4th story n summanizes this story and the one he saved from the previous



 

Decode String 

Description


You are learning cryptography and as a challenge, your friend gave you this problem to decode. You are given an encoded string. To decode the string, the encoded string is read one character at a time and the following steps are taken
• If the character read is a letter, that letter is written in the decoded string
If the character read is a digit, say d, the entire decoded string is
repeatedly written d-1 more times in total
Finally, given an integer k, you need to return the ith letter from the decoded
string.


Input format:

 

  • The first line will have a strings
  • The second line will have an integer k

Output format:


The character on the ith index of the decoded strings consists of lowercase English letters and digits 2 through

  • 2 <= s.length <= 100
  • s consists of lowercase English letters and digits 2 through 9.
  • s start with a letter
  • 1 <= k <=100
  • It is guarenteed that  k is less than or equal the length the decoded string
  • The decoded string is guaranteed to have less than 263 letters.

 

Sample Input

ha22
5


Sample Output

h

Explanation

The deccoded string is "hahahaha"

The 5th letter is "h"



Birthday Conundrum

Friend A wants to surprise Friend B on her birthday She ha a bar which has a colection of beads with alphabets onthem Friend A wants to build a neckace consisting of herfrends name and her name This shall be her gift on her birthday and she wants to construct the longest necklace
possible however only using her name or her friends name or a combination of both their names. Can you help Friend A come up with the longest length of the string that sheneeds to order from Pincode App?


Note: The letter once piciced up, can't be repeated


Input Format


First line represents the Box.
Second line represents the friend A 's name 

Third line represents the friend B 's name 


Output Format:


The length of the longest string that can be constructed

 

Constraints


Box consists only of uppercase English letters.


1< Box length « 10e7
1 <= FriendA.length « 10e5
1 <= FriendB.length « 10e5

Example 1

 

ABCRNMXYZANBCA
ANNA
RAM

Sample Output

7

Explanation:


One can pick letters ANAN to form ANNA and
'RMA to form RAM
So the longest letter of the string is 7.



Reduce to Zero

Bob is given a non-negative number  N and he is expected to bring taht  number to 0 . He can perform any of the 2 Operations on N in each move 

1) If we take 2 integers and and b where N = a*b then we can change N = max(a,b)

2 Decrease the value of N by 1


Determine the minimum number of moves required to reduce the value of N to 0

Example

Input - 3

Output - 3

Explanation

3 ---> 2 ---> 1 ----> 0

Input Format 

  • Non negative number N

Output Format 

  • For each test cas e . Determine the minimum nuber of moves required to reduce the value from N to 0

Constraints 

  • 0 <= N <= 10^6
SAMPLE INPUT 
3

SAMPLE OUTPUT 
3

Explanation 

3 --->2 --->1 -->0

 

 

 

ADD COMMENTlink 17 months ago PoGo 2.4k
1
Entering edit mode

///REDUCE TO ZERO

#include <bits/stdc++.h>
using namespace std;

vector<int>f(int n){
  
  vector<int>v;
  for(int i=2;i<=sqrt(n);i++)if(n%i==0)v.push_back(n/i);
  return v;
}

int main() {
    int n;
    cin>>n;
    
    vector<int>dp(n+1,INT_MAX);
    dp[0]=0;
    dp[1]=1;
    dp[2]=2;
    
    for(int i=2;i<=n;i++){
      dp[i]=dp[i-1]+1;
       for(auto fac :f(i)){
         dp[i]=min(dp[i] , 1 + dp[fac]);
       }
    }
    cout<<dp[n]<<endl;
    return 0;
}
 

ADD COMMENTlink 17 months ago mrphenomenal • 10
1
Entering edit mode

// QNO-1 STORY TELLER

#include <bits/stdc++.h>
using namespace std;

int f(int a, int b, int c){
    int ts = a/b;
    int cs = ts;
    while(cs >= c){
        int ns = cs/c;
        cs = cs%c;
        cs+=ns;
        ts+=ns;
    }
    return ts;
}

int main(){
    int t;
    cin>>t;
    while(t--){
        int a, b, c;
        cin>>a>>b>>c;
        cout<<f(a, b, c)<<endl;
    }
}
 

ADD COMMENTlink 16 months ago Vishwajeet Kumar • 10
0
Entering edit mode

 

 

ADD COMMENTlink 14 months ago Aditya Sinha • 0

Login before adding your answer.

Similar Posts
Loading Similar Posts