Number of Credits Codechef Solution

ByBrokenprogrammers

Dec 23, 2022

Hello Programmers In this post, you will know how to solve the Number of Credits Codechef Solution. The Problem Code is CREDS.

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Codechef by yourself. If you find any difficulty after trying several times, then you can look for solutions.

Problem

Chef has a binary string S. He can modify it by choosing any subsequence of length 3 from it and deleting the first and last character of the subsequence.

For example, if S = textcolor{red}{11}01textcolor{red}{0}1S=110101, Chef can choose the subsequence marked in red and delete its first and last characters, obtaining the string S = 1011S=1011.

Chef wonders what is the lexicographically largest string he can obtain by modifying the original string using a finite number of operations. Please help Chef in this task.

Note: A binary string AA is said to be lexicographically larger than another binary string BB if:

• BB is a proper prefix of AA (for example, 101101 is lexicographically larger than 1010); or
• There exists an index ii such that A_1 = B_1, A_2 = B_2, ldots, A_{i-1} = B_{i-1}A1​=B1​,A2​=B2​,…,Ai−1​=Bi−1​ and A_i gt B_iAi​>Bi.

Input Format

• The first line of input will contain a single integer TT, denoting the number of test cases.
• Each test case consists of a single line of input containing the original binary string SS.

Output Format

For each test case, output on a new line the lexicographically largest string Chef can obtain.

Constraints

• 1 leq T leq 2cdot 10^41≤T≤2⋅104
• 3 leq |S| leq 10^53≤∣S∣≤105
• SS is a binary string, i.e, only contains the characters 00 and 11 in it
• The sum of |S|∣S∣ over all test cases won’t exceed 3cdot 10^53⋅105.

Input

```4
101
1010
0000
0001```

Output

```101
11
0000
0```

Explanation:

Test case 11: It is optimal to not perform any moves.

Test case 22: In one move, by choosing the subsequence 1textcolor{red}{010}1010, the string can be made into 1111, which is the lexicographically largest possible.

Test case 33: It is optimal to not perform any move.

Number of Credits Codechef Solution in CPP

```#include <iostream>
using namespace std;
int main() {
int t;
cin>>t;
while(t--)
{
int x,y,z;
cin>>x>>y>>z;
int a=x*4;
int b=y*2;
cout<<a+b<<endl;
}
return 0;
}
```

Number of Credits Codechef Solution in JAVA

```/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner Sc=new Scanner(System.in);
int T= Sc.nextInt();
for(int i=1;i<=T;i++){
int X= Sc.nextInt();
int Y= Sc.nextInt();
int Z= Sc.nextInt();
System.out.println(4*X+ 2*Y + 0*Z);
}
}
}
```

Number of Credits Codechef Solution in Python

```# cook your dish here
T=int(input())
for i in range(T):
x,y,z=map(int,input().split(' '))
print(x*4+y*2)```

Disclaimer: The above Problem (Number of Credits) is generated by CodeChef but the solution is provided by BrokenProgrammers. This tutorial is only for Educational and Learning purpose.

Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.