Print the maximum number of A's. Print -1, if N is greater than 75. - Codeprg

Breaking

programing News Travel Computer Engineering Science Blogging Earning

Saturday 11 July 2020

Print the maximum number of A's. Print -1, if N is greater than 75.

Print the maximum number of A's. Print -1, if N is greater than 75.
Imagine you have a special keyboard with the following keys: 
Key 1:  Prints 'A' on screen
Key 2: (Ctrl-A): Select screen
Key 3: (Ctrl-C): Copy selection to buffer
Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. If you can only press the keyboard for N times (with the above four keys), write a program to produce maximum numbers of A's. That is to say, the input parameter is N (No. of keys that you can press), the output is M (No. of As that you can produce).

Print the maximum number of A's. Print -1, if N is greater than 75.

Example:
Input:
2
3
7

Output:
3
9


#include <bits/stdc++.h>


using namespace std;

int stpcopy(int n) {

// when n greater than 75 return -1

    if (n > 75)

        return -1;

    else {

    //when n is less than equal to 6

    //then return n bcz no use of these (clt+a,c,v)

        if (n <= 6)

            return n;

        int a[n + 1];

        for (int i = 1; i <= 6; ++i) {

            a[i] = i;

        }

        for (int i = 7; i <= n; ++i) {

            a[i] = max(3 * a[i - 4], 4 * a[i - 5]);

        }

        return a[n];

    }

}

int main() {

    //code

    int t;

    cin >> t;

    while (t--) {

        int n;

        cin >> n;

        cout << stpcopy(n) << endl;

    }

    return 0;

}