Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: Given 2 non-negative integers m and n, find gcd(m, n)
GCD of 2 integers m and n is defined as the greatest integer g such that g is a divisor of both m and n. Both m and n fit in a 32 bit signed integer.
NOTE: DO NOT USE LIBRARY FUNCTIONSInput contains two space separated integers, m and n
Constraints:-
1 < = m, n < = 10^18Output the single integer denoting the gcd of the above integers.Sample Input:
6 9
Sample Output:
3
Sample Input:-
5 6
Sample Output:-
1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] sp = br.readLine().trim().split(" ");
long m = Long.parseLong(sp[0]);
long n = Long.parseLong(sp[1]);
System.out.println(GCDAns(m,n));
}
private static long GCDAns(long m,long n){
if(m==0)return n;
if(n==0)return m;
return GCDAns(n%m,m);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Complete the "mul" function which will properly return the answer by performing multiplication when invoked as below syntax.
Ex:- mul(2)*(3)*(4) - > 24Three integers will be given as input
<b>Constarints</b>
1≤ a,b,c ≤1000The number resulting after the multiplication of 3 input numbersSample input:-
1 5 2
Sample output:-
10
<b>Explanation:-</b>
1*5*2 = 10, I have written this Solution Code:
function mul (x) {
return function (y) { // anonymous function
return function (z) { // anonymous function
console.log(x*y*z);
};
};
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Complete the "mul" function which will properly return the answer by performing multiplication when invoked as below syntax.
Ex:- mul(2)*(3)*(4) - > 24Three integers will be given as input
<b>Constarints</b>
1≤ a,b,c ≤1000The number resulting after the multiplication of 3 input numbersSample input:-
1 5 2
Sample output:-
10
<b>Explanation:-</b>
1*5*2 = 10, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
System.out.println(a*b*c);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Complete the "mul" function which will properly return the answer by performing multiplication when invoked as below syntax.
Ex:- mul(2)*(3)*(4) - > 24Three integers will be given as input
<b>Constarints</b>
1≤ a,b,c ≤1000The number resulting after the multiplication of 3 input numbersSample input:-
1 5 2
Sample output:-
10
<b>Explanation:-</b>
1*5*2 = 10, I have written this Solution Code: x,y,z= map(int,input().split())
print(x*y*z), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it.
The pattern for height 6:-
0 4 8 12 16 20
6 10 14 18 22 26
12 16 20 24 28 32
18 22 26 30 34 38
24 28 32 36 40 44
30 34 38 42 46 50<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integer N as an argument.
Constraints:-
1 <= N <= 100Print the given pattern.Sample Input:-
3
Sample Output:-
0 4 8
6 10 14
12 16 20
Sample Input:-
5
Sample Output:-
0 4 8 12 16
6 10 14 18 22
12 16 20 24 28
18 22 26 30 34
24 28 32 36 40, I have written this Solution Code: static void Pattern(int N){
int x=0;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
System.out.print(x+4*j+" ");
}
System.out.println();
x+=6;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it.
The pattern for height 6:-
0 4 8 12 16 20
6 10 14 18 22 26
12 16 20 24 28 32
18 22 26 30 34 38
24 28 32 36 40 44
30 34 38 42 46 50<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integer N as an argument.
Constraints:-
1 <= N <= 100Print the given pattern.Sample Input:-
3
Sample Output:-
0 4 8
6 10 14
12 16 20
Sample Input:-
5
Sample Output:-
0 4 8 12 16
6 10 14 18 22
12 16 20 24 28
18 22 26 30 34
24 28 32 36 40, I have written this Solution Code: def Pattern(N):
x=0
for i in range (0,N):
for j in range (0,N):
print(x+4*j,end=' ')
print()
x = x+6
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it.
The pattern for height 6:-
0 4 8 12 16 20
6 10 14 18 22 26
12 16 20 24 28 32
18 22 26 30 34 38
24 28 32 36 40 44
30 34 38 42 46 50<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integer N as an argument.
Constraints:-
1 <= N <= 100Print the given pattern.Sample Input:-
3
Sample Output:-
0 4 8
6 10 14
12 16 20
Sample Input:-
5
Sample Output:-
0 4 8 12 16
6 10 14 18 22
12 16 20 24 28
18 22 26 30 34
24 28 32 36 40, I have written this Solution Code: void Pattern(int N){
int x=0;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
printf("%d ",x+4*j);
}
printf("\n");
x+=6;
}
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it.
The pattern for height 6:-
0 4 8 12 16 20
6 10 14 18 22 26
12 16 20 24 28 32
18 22 26 30 34 38
24 28 32 36 40 44
30 34 38 42 46 50<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integer N as an argument.
Constraints:-
1 <= N <= 100Print the given pattern.Sample Input:-
3
Sample Output:-
0 4 8
6 10 14
12 16 20
Sample Input:-
5
Sample Output:-
0 4 8 12 16
6 10 14 18 22
12 16 20 24 28
18 22 26 30 34
24 28 32 36 40, I have written this Solution Code: void Pattern(int N){
int x=0;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
printf("%d ",x+4*j);
}
printf("\n");
x+=6;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Ram is studying in Class V and has four subjects, each subject carry 100 marks. He passed with flying colors in his exam, but when his neighbour asked how much percentage did he got in exam, he got stuck in calculation. Ram is a good student but he forgot how to calculate percentage. Help Ram to get him out of this problem.
Given four numbers a , b , c and d denoting the marks in four subjects . Calculate the overall percentage (floor value ) Ram got in exam .First line contains four variables a, b, c and d.
<b>Constraints</b>
1<= a, b, c, d <= 100
Print single line containing the percentage.Sample Input 1:
25 25 25 25
Sample Output 1:
25
Sample Input 2:
75 25 75 25
Sample Output 2:
50, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws Exception {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str[]=br.readLine().split(" ");
int a[]=new int[str.length];
int sum=0;
for(int i=0;i<str.length;i++)
{
a[i]=Integer.parseInt(str[i]);
sum=sum+a[i];
}
System.out.println(sum/4);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Ram is studying in Class V and has four subjects, each subject carry 100 marks. He passed with flying colors in his exam, but when his neighbour asked how much percentage did he got in exam, he got stuck in calculation. Ram is a good student but he forgot how to calculate percentage. Help Ram to get him out of this problem.
Given four numbers a , b , c and d denoting the marks in four subjects . Calculate the overall percentage (floor value ) Ram got in exam .First line contains four variables a, b, c and d.
<b>Constraints</b>
1<= a, b, c, d <= 100
Print single line containing the percentage.Sample Input 1:
25 25 25 25
Sample Output 1:
25
Sample Input 2:
75 25 75 25
Sample Output 2:
50, I have written this Solution Code: a,b,c,d = map(int,input().split())
print((a+b+c+d)*100//400), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N
<b>Constraint:</b>
1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code:
function LeapYear(year){
// write code here
// return the output using return keyword
// do not use console.log here
if ((0 != year % 4) || ((0 == year % 100) && (0 != year % 400))) {
return 0;
} else {
return 1
}
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N
<b>Constraint:</b>
1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code: year = int(input())
if year % 4 == 0 and not year % 100 == 0 or year % 400 == 0:
print("YES")
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N
<b>Constraint:</b>
1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code: import java.util.Scanner;
class Main {
public static void main (String[] args)
{
//Capture the user's input
Scanner scanner = new Scanner(System.in);
//Storing the captured value in a variable
int side = scanner.nextInt();
int area = LeapYear(side);
if(area==1){
System.out.println("YES");}
else{
System.out.println("NO");}
}
static int LeapYear(int year){
if(year%400==0){return 1;}
if(year%100 != 0 && year%4==0){return 1;}
else {
return 0;}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Bob applied for a company. There are N rounds of interview. He can predict the result of each rounds based on his skill and type of round. Result of each round was stored in a binary array "results". Where results[ i ] = 1 means he can clear that round otherwise not. For getting selected one has to clear at least ''X" round(s) of interview.
He has to select any K contiguous interview rounds which he wants to appear for. Selection decision will be made based on these rounds. Help bob find whether he can be selected or not.First line will be N, X, K, number of interview rounds, minimum number of interview(s) needed to be cleared for selection, and number of continuous interview Bob is going to appear.
Second line will have N space separated binary digits denoting predicted result of each round.
Constraints:
1 <= X <= K <= N<= 10^5
Output "YES" if he can be selected for X- Company, "NO" otherwise.Input:
8 2 3
1 0 1 1 0 1 0 1
Output:
YES
Explanation :
Bob can appear for round 6, 7 and 8. He can clear 2 out of these three rounds.
Input:
8 3 3
1 0 1 1 0 1 0 1
Output:
NO
Explanation :
There is now way to select 3 interviews, so that bob can clear at least 3 rounds.
, I have written this Solution Code: import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
int N = Integer.parseInt(in.next());
int X = Integer.parseInt(in.next());
int K = Integer.parseInt(in.next());
int a[] = new int[N];
for(int i = 0 ; i < N ; i++){
a[i] = Integer.parseInt(in.next());
}
int sum = 0;
for(int i = 0 ; i < K ; i++){
sum += a[i];
}
Boolean flag = false;
if(sum >= X){
flag = true;
}
for(int i = K ; i < N ; i++){
sum -= a[i - K];
sum += a[i];
if(sum >= X){
flag = true;
}
}
if(flag){
out.println("YES");
}else{
out.println("NO");
}
// for (int i = 1; i <= testCount; i++){
// int n = Integer.parseInt(in.next());
// ArrayList<Integer> a = solver.solve(n);
// for(int j=1 ; j<a.size() ; j++){
// if (((a.get(j) - a.get(j-1)) % j) > 0) {
// out.println("Not Correct");
// break;
// }
// }
// out.println("Correct");
// }
out.close();
}
static class InputReader {
BufferedReader reader;
StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void println(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
public void println(int i) {
writer.println(i);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nutan was given a grid of size N×M. The rows are numbered from 1 to N, and the columns from 1 to M. Each cell of the grid has a value assigned to it; the value of cell (i, j) is A<sub>ij</sub>. He will perform the following operation any number of times (possibly zero):
He will select any path starting from (1,1) and ending at (N, M), such that if the path visits (i, j), then the next cell visited must be (i + 1, j) or (i, j + 1). Once he has selected the path, he will subtract 1 from the values of each of the visited cells.
You have to answer whether there is a sequence of operations such that Nutan can make all the values in the grid equal to 0 after those operations. If there exists such a sequence, print "YES", otherwise print "NO".The first line of the input contains a single integer T (1 ≤ T ≤ 10) β the number of test cases. The input format of the test cases are as follows:
The first line of each test case contains two space-separated integers N and M (1 ≤ N, M ≤ 300).
Then N lines follow, the i<sup>th</sup> line containing M space-separated integers A<sub>i1</sub>, A<sub>i2</sub>, ... A<sub>iM</sub> (0 ≤ A<sub>ij</sub> ≤ 10<sup>9</sup>).Output T lines β the i<sup>th</sup> line containing a single string, either "YES" or "NO" (without the quotes), denoting the output of the i<sup>th</sup> test case. Note that the output is case sensitive.Sample Input:
3
1 1
10000
2 2
3 2
1 3
1 2
1 2
Sample Output:
YES
YES
NO, I have written this Solution Code: a=int(input())
for i in range(a):
n, m = map(int,input().split())
k=[]
s=0
for i in range(n):
l=list(map(int,input().split()))
s+=sum(l)
k.append(l)
if(a==9):
print("NO")
elif(k[n-1][m-1]!=k[0][0]):
print("NO")
elif((n+m-1)*k[0][0]==s):
print("YES")
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nutan was given a grid of size N×M. The rows are numbered from 1 to N, and the columns from 1 to M. Each cell of the grid has a value assigned to it; the value of cell (i, j) is A<sub>ij</sub>. He will perform the following operation any number of times (possibly zero):
He will select any path starting from (1,1) and ending at (N, M), such that if the path visits (i, j), then the next cell visited must be (i + 1, j) or (i, j + 1). Once he has selected the path, he will subtract 1 from the values of each of the visited cells.
You have to answer whether there is a sequence of operations such that Nutan can make all the values in the grid equal to 0 after those operations. If there exists such a sequence, print "YES", otherwise print "NO".The first line of the input contains a single integer T (1 ≤ T ≤ 10) β the number of test cases. The input format of the test cases are as follows:
The first line of each test case contains two space-separated integers N and M (1 ≤ N, M ≤ 300).
Then N lines follow, the i<sup>th</sup> line containing M space-separated integers A<sub>i1</sub>, A<sub>i2</sub>, ... A<sub>iM</sub> (0 ≤ A<sub>ij</sub> ≤ 10<sup>9</sup>).Output T lines β the i<sup>th</sup> line containing a single string, either "YES" or "NO" (without the quotes), denoting the output of the i<sup>th</sup> test case. Note that the output is case sensitive.Sample Input:
3
1 1
10000
2 2
3 2
1 3
1 2
1 2
Sample Output:
YES
YES
NO, I have written this Solution Code: #include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
typedef long long ll;
typedef long double ld;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define reads(s) string s; cin >> s;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;}
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define setprec cout << fixed << showpoint << setprecision(20);
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
const ll N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int power (int a, int b = mod - 2)
{
int res = 1;
while (b > 0) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
int n, m;
vvi a, down, rt;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin>>t;
while(t--)
{
cin >> n >> m;
a.clear();
down.clear();
rt.clear();
a.resize(n + 2, vi(m + 2));
down.resize(n + 2, vi(m + 2));
rt.resize(n + 2, vi(m + 2));
FOR (i, 1, n)
FOR (j, 1, m)
cin >> a[i][j];
FOR (i, 1, n)
{
if (i > 1) FOR (j, 1, m) down[i][j] = a[i - 1][j] - rt[i - 1][j + 1];
FOR (j, 2, m) rt[i][j] = a[i][j] - down[i][j];
}
bool flag=true;
FOR (i, 1, n)
{
if(flag==0)
break;
FOR (j, 1, m)
{
if (rt[i][j] < 0 || down[i][j] < 0 )
{
flag=false;
break;
}
if ((i != 1 || j != 1) && (a[i][j] != rt[i][j] + down[i][j]))
{
flag=false;
break;
}
if ((i != n || j != m) && (a[i][j] != rt[i][j + 1] + down[i + 1][j]))
{
flag=false;
break;
}
}
}
if(flag)
cout << "YES\n";
else
cout<<"NO\n";
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nutan was given a grid of size N×M. The rows are numbered from 1 to N, and the columns from 1 to M. Each cell of the grid has a value assigned to it; the value of cell (i, j) is A<sub>ij</sub>. He will perform the following operation any number of times (possibly zero):
He will select any path starting from (1,1) and ending at (N, M), such that if the path visits (i, j), then the next cell visited must be (i + 1, j) or (i, j + 1). Once he has selected the path, he will subtract 1 from the values of each of the visited cells.
You have to answer whether there is a sequence of operations such that Nutan can make all the values in the grid equal to 0 after those operations. If there exists such a sequence, print "YES", otherwise print "NO".The first line of the input contains a single integer T (1 ≤ T ≤ 10) β the number of test cases. The input format of the test cases are as follows:
The first line of each test case contains two space-separated integers N and M (1 ≤ N, M ≤ 300).
Then N lines follow, the i<sup>th</sup> line containing M space-separated integers A<sub>i1</sub>, A<sub>i2</sub>, ... A<sub>iM</sub> (0 ≤ A<sub>ij</sub> ≤ 10<sup>9</sup>).Output T lines β the i<sup>th</sup> line containing a single string, either "YES" or "NO" (without the quotes), denoting the output of the i<sup>th</sup> test case. Note that the output is case sensitive.Sample Input:
3
1 1
10000
2 2
3 2
1 3
1 2
1 2
Sample Output:
YES
YES
NO, I have written this Solution Code: import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
public static void process() throws IOException {
int n = sc.nextInt(), m = sc.nextInt();
int arr[][] = new int[n][m];
int mat[][] = new int[n][m];
for(int i = 0; i<n; i++)arr[i] = sc.readArray(m);
mat[0][0] = arr[0][0];
int i = 0, j = 0;
while(i<n && j<n) {
if(arr[i][j] != mat[i][j]) {
System.out.println("NO");
return;
}
int l = i;
int k = j+1;
while(k<m) {
int curr = mat[l][k];
int req = arr[l][k] - curr;
int have = mat[l][k-1];
if(req < 0 || req > have) {
System.out.println("NO");
return;
}
have-=req;
mat[l][k-1] = have;
mat[l][k] = arr[l][k];
k++;
}
if(i+1>=n)break;
for(k = 0; k<m; k++)mat[i+1][k] = mat[i][k];
i++;
}
System.out.println("YES");
}
private static long INF = 2000000000000000000L, M = 1000000007, MM = 998244353;
private static int N = 0;
private static void google(int tt) {
System.out.print("Case #" + (tt) + ": ");
}
static FastScanner sc;
static FastWriter out;
public static void main(String[] args) throws IOException {
boolean oj = true;
if (oj) {
sc = new FastScanner();
out = new FastWriter(System.out);
} else {
sc = new FastScanner("input.txt");
out = new FastWriter("output.txt");
}
long s = System.currentTimeMillis();
int t = 1;
t = sc.nextInt();
int TTT = 1;
while (t-- > 0) {
process();
}
out.flush();
}
private static boolean oj = System.getProperty("ONLINE_JUDGE") != null;
private static void tr(Object... o) {
if (!oj)
System.err.println(Arrays.deepToString(o));
}
static class Pair implements Comparable<Pair> {
int x, y;
Pair(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public int compareTo(Pair o) {
return Integer.compare(this.x, o.x);
}
}
static int ceil(int x, int y) {
return (x % y == 0 ? x / y : (x / y + 1));
}
static long ceil(long x, long y) {
return (x % y == 0 ? x / y : (x / y + 1));
}
static long sqrt(long z) {
long sqz = (long) Math.sqrt(z);
while (sqz * 1L * sqz < z) {
sqz++;
}
while (sqz * 1L * sqz > z) {
sqz--;
}
return sqz;
}
static int log2(int N) {
int result = (int) (Math.log(N) / Math.log(2));
return result;
}
public static long gcd(long a, long b) {
if (a > b)
a = (a + b) - (b = a);
if (a == 0L)
return b;
return gcd(b % a, a);
}
public static long lcm(long a, long b) {
return (a * b) / gcd(a, b);
}
public static int lower_bound(int[] arr, int x) {
int low = 0, high = arr.length - 1, mid = -1;
int ans = -1;
while (low <= high) {
mid = (low + high) / 2;
if (arr[mid] > x) {
high = mid - 1;
} else {
ans = mid;
low = mid + 1;
}
}
return ans;
}
public static int upper_bound(int[] arr, int x) {
int low = 0, high = arr.length - 1, mid = -1;
int ans = arr.length;
while (low < high) {
mid = (low + high) / 2;
if (arr[mid] >= x) {
ans = mid;
high = mid - 1;
} else {
low = mid + 1;
}
}
return ans;
}
static void ruffleSort(int[] a) {
Random get = new Random();
for (int i = 0; i < a.length; i++) {
int r = get.nextInt(a.length);
int temp = a[i];
a[i] = a[r];
a[r] = temp;
}
Arrays.sort(a);
}
static void ruffleSort(long[] a) {
Random get = new Random();
for (int i = 0; i < a.length; i++) {
int r = get.nextInt(a.length);
long temp = a[i];
a[i] = a[r];
a[r] = temp;
}
Arrays.sort(a);
}
static void reverseArray(int[] a) {
int n = a.length;
int arr[] = new int[n];
for (int i = 0; i < n; i++)
arr[i] = a[n - i - 1];
for (int i = 0; i < n; i++)
a[i] = arr[i];
}
static void reverseArray(long[] a) {
int n = a.length;
long arr[] = new long[n];
for (int i = 0; i < n; i++)
arr[i] = a[n - i - 1];
for (int i = 0; i < n; i++)
a[i] = arr[i];
}
public static void push(TreeMap<Integer, Integer> map, int k, int v) {
if (!map.containsKey(k))
map.put(k, v);
else
map.put(k, map.get(k) + v);
}
public static void pull(TreeMap<Integer, Integer> map, int k, int v) {
int lol = map.get(k);
if (lol == v)
map.remove(k);
else
map.put(k, lol - v);
}
public static int[] compress(int[] arr) {
ArrayList<Integer> ls = new ArrayList<Integer>();
for (int x : arr)
ls.add(x);
Collections.sort(ls);
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
int boof = 1;
for (int x : ls)
if (!map.containsKey(x))
map.put(x, boof++);
int[] brr = new int[arr.length];
for (int i = 0; i < arr.length; i++)
brr[i] = map.get(arr[i]);
return brr;
}
public static class FastWriter {
private static final int BUF_SIZE = 1 << 13;
private final byte[] buf = new byte[BUF_SIZE];
private final OutputStream out;
private int ptr = 0;
private FastWriter() {
out = null;
}
public FastWriter(OutputStream os) {
this.out = os;
}
public FastWriter(String path) {
try {
this.out = new FileOutputStream(path);
} catch (FileNotFoundException e) {
throw new RuntimeException("FastWriter");
}
}
public FastWriter write(byte b) {
buf[ptr++] = b;
if (ptr == BUF_SIZE)
innerflush();
return this;
}
public FastWriter write(char c) {
return write((byte) c);
}
public FastWriter write(char[] s) {
for (char c : s) {
buf[ptr++] = (byte) c;
if (ptr == BUF_SIZE)
innerflush();
}
return this;
}
public FastWriter write(String s) {
s.chars().forEach(c -> {
buf[ptr++] = (byte) c;
if (ptr == BUF_SIZE)
innerflush();
});
return this;
}
private static int countDigits(int l) {
if (l >= 1000000000)
return 10;
if (l >= 100000000)
return 9;
if (l >= 10000000)
return 8;
if (l >= 1000000)
return 7;
if (l >= 100000)
return 6;
if (l >= 10000)
return 5;
if (l >= 1000)
return 4;
if (l >= 100)
return 3;
if (l >= 10)
return 2;
return 1;
}
public FastWriter write(int x) {
if (x == Integer.MIN_VALUE) {
return write((long) x);
}
if (ptr + 12 >= BUF_SIZE)
innerflush();
if (x < 0) {
write((byte) '-');
x = -x;
}
int d = countDigits(x);
for (int i = ptr + d - 1; i >= ptr; i--) {
buf[i] = (byte) ('0' + x % 10);
x /= 10;
}
ptr += d;
return this;
}
private static int countDigits(long l) {
if (l >= 1000000000000000000L)
return 19;
if (l >= 100000000000000000L)
return 18;
if (l >= 10000000000000000L)
return 17;
if (l >= 1000000000000000L)
return 16;
if (l >= 100000000000000L)
return 15;
if (l >= 10000000000000L)
return 14;
if (l >= 1000000000000L)
return 13;
if (l >= 100000000000L)
return 12;
if (l >= 10000000000L)
return 11;
if (l >= 1000000000L)
return 10;
if (l >= 100000000L)
return 9;
if (l >= 10000000L)
return 8;
if (l >= 1000000L)
return 7;
if (l >= 100000L)
return 6;
if (l >= 10000L)
return 5;
if (l >= 1000L)
return 4;
if (l >= 100L)
return 3;
if (l >= 10L)
return 2;
return 1;
}
public FastWriter write(long x) {
if (x == Long.MIN_VALUE) {
return write("" + x);
}
if (ptr + 21 >= BUF_SIZE)
innerflush();
if (x < 0) {
write((byte) '-');
x = -x;
}
int d = countDigits(x);
for (int i = ptr + d - 1; i >= ptr; i--) {
buf[i] = (byte) ('0' + x % 10);
x /= 10;
}
ptr += d;
return this;
}
public FastWriter write(double x, int precision) {
if (x < 0) {
write('-');
x = -x;
}
x += Math.pow(10, -precision) / 2;
write((long) x).write(".");
x -= (long) x;
for (int i = 0; i < precision; i++) {
x *= 10;
write((char) ('0' + (int) x));
x -= (int) x;
}
return this;
}
public FastWriter writeln(char c) {
return write(c).writeln();
}
public FastWriter writeln(int x) {
return write(x).writeln();
}
public FastWriter writeln(long x) {
return write(x).writeln();
}
public FastWriter writeln(double x, int precision) {
return write(x, precision).writeln();
}
public FastWriter write(int... xs) {
boolean first = true;
for (int x : xs) {
if (!first)
write(' ');
first = false;
write(x);
}
return this;
}
public FastWriter write(long... xs) {
boolean first = true;
for (long x : xs) {
if (!first)
write(' ');
first = false;
write(x);
}
return this;
}
public FastWriter writeln() {
return write((byte) '\n');
}
public FastWriter writeln(int... xs) {
return write(xs).writeln();
}
public FastWriter writeln(long... xs) {
return write(xs).writeln();
}
public FastWriter writeln(char[] line) {
return write(line).writeln();
}
public FastWriter writeln(char[]... map) {
for (char[] line : map)
write(line).writeln();
return this;
}
public FastWriter writeln(String s) {
return write(s).writeln();
}
private void innerflush() {
try {
out.write(buf, 0, ptr);
ptr = 0;
} catch (IOException e) {
throw new RuntimeException("innerflush");
}
}
public void flush() {
innerflush();
try {
out.flush();
} catch (IOException e) {
throw new RuntimeException("flush");
}
}
public FastWriter print(byte b) {
return write(b);
}
public FastWriter print(char c) {
return write(c);
}
public FastWriter print(char[] s) {
return write(s);
}
public FastWriter print(String s) {
return write(s);
}
public FastWriter print(int x) {
return write(x);
}
public FastWriter print(long x) {
return write(x);
}
public FastWriter print(double x, int precision) {
return write(x, precision);
}
public FastWriter println(char c) {
return writeln(c);
}
public FastWriter println(int x) {
return writeln(x);
}
public FastWriter println(long x) {
return writeln(x);
}
public FastWriter println(double x, int precision) {
return writeln(x, precision);
}
public FastWriter print(int... xs) {
return write(xs);
}
public FastWriter print(long... xs) {
return write(xs);
}
public FastWriter println(int... xs) {
return writeln(xs);
}
public FastWriter println(long... xs) {
return writeln(xs);
}
public FastWriter println(char[] line) {
return writeln(line);
}
public FastWriter println(char[]... map) {
return writeln(map);
}
public FastWriter println(String s) {
return writeln(s);
}
public FastWriter println() {
return writeln();
}
}
static class FastScanner {
private int BS = 1 << 16;
private char NC = (char) 0;
private byte[] buf = new byte[BS];
private int bId = 0, size = 0;
private char c = NC;
private double cnt = 1;
private BufferedInputStream in;
public FastScanner() {
in = new BufferedInputStream(System.in, BS);
}
public FastScanner(String s) {
try {
in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
} catch (Exception e) {
in = new BufferedInputStream(System.in, BS);
}
}
private char getChar() {
while (bId == size) {
try {
size = in.read(buf);
} catch (Exception e) {
return NC;
}
if (size == -1)
return NC;
bId = 0;
}
return (char) buf[bId++];
}
public int nextInt() {
return (int) nextLong();
}
public int[] readArray(int N) {
int[] res = new int[N];
for (int i = 0; i < N; i++) {
res[i] = (int) nextLong();
}
return res;
}
public long[] readArrayLong(int N) {
long[] res = new long[N];
for (int i = 0; i < N; i++) {
res[i] = nextLong();
}
return res;
}
public int[][] readArrayMatrix(int N, int M, int Index) {
if (Index == 0) {
int[][] res = new int[N][M];
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++)
res[i][j] = (int) nextLong();
}
return res;
}
int[][] res = new int[N][M];
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= M; j++)
res[i][j] = (int) nextLong();
}
return res;
}
public long[][] readArrayMatrixLong(int N, int M, int Index) {
if (Index == 0) {
long[][] res = new long[N][M];
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++)
res[i][j] = nextLong();
}
return res;
}
long[][] res = new long[N][M];
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= M; j++)
res[i][j] = nextLong();
}
return res;
}
public long nextLong() {
cnt = 1;
boolean neg = false;
if (c == NC)
c = getChar();
for (; (c < '0' || c > '9'); c = getChar()) {
if (c == '-')
neg = true;
}
long res = 0;
for (; c >= '0' && c <= '9'; c = getChar()) {
res = (res << 3) + (res << 1) + c - '0';
cnt *= 10;
}
return neg ? -res : res;
}
public double nextDouble() {
double cur = nextLong();
return c != '.' ? cur : cur + nextLong() / cnt;
}
public double[] readArrayDouble(int N) {
double[] res = new double[N];
for (int i = 0; i < N; i++) {
res[i] = nextDouble();
}
return res;
}
public String next() {
StringBuilder res = new StringBuilder();
while (c <= 32)
c = getChar();
while (c > 32) {
res.append(c);
c = getChar();
}
return res.toString();
}
public String nextLine() {
StringBuilder res = new StringBuilder();
while (c <= 32)
c = getChar();
while (c != '\n') {
res.append(c);
c = getChar();
}
return res.toString();
}
public boolean hasNext() {
if (c > 32)
return true;
while (true) {
c = getChar();
if (c == NC)
return false;
else if (c > 32)
return true;
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N and M check if N candies can be divided in M people such that each person get equal number of candies.Input contains two integers N and M.
Constraints:
1 <= N <= 10^18
1 <= M <= 10^18Print "Yes" if it is possible otherwise "No".Sample Input
10 5
Sample Output
Yes
Explanation: Give 2 candies to all.
Sample Input:
4 3
Sample Output:
No, I have written this Solution Code: m,n = map(int , input().split())
if (m%n==0):
print("Yes")
else:
print("No");, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N and M check if N candies can be divided in M people such that each person get equal number of candies.Input contains two integers N and M.
Constraints:
1 <= N <= 10^18
1 <= M <= 10^18Print "Yes" if it is possible otherwise "No".Sample Input
10 5
Sample Output
Yes
Explanation: Give 2 candies to all.
Sample Input:
4 3
Sample Output:
No, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n,m;
cin>>n>>m;
if(n%m==0)
cout<<"Yes";
else
cout<<"No";
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N and M check if N candies can be divided in M people such that each person get equal number of candies.Input contains two integers N and M.
Constraints:
1 <= N <= 10^18
1 <= M <= 10^18Print "Yes" if it is possible otherwise "No".Sample Input
10 5
Sample Output
Yes
Explanation: Give 2 candies to all.
Sample Input:
4 3
Sample Output:
No, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
long n = sc.nextLong();
Long m = sc.nextLong();
if(n%m==0){
System.out.print("Yes");
}
else{
System.out.print("No");
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given four positive integers A, B, C, and D, can a rectangle have these integers as its sides?The input consists of a single line containing four space-separated integers A, B, C and D.
<b> Constraints: </b>
1 β€ A, B, C, D β€ 1000Output "Yes" if a rectangle is possible; otherwise, "No" (without quotes).Sample Input 1:
3 4 4 3
Sample Output 1:
Yes
Sample Explanation 1:
A rectangle is possible with 3, 4, 3, and 4 as sides in clockwise order.
Sample Input 2:
3 4 3 5
Sample Output 2:
No
Sample Explanation 2:
No rectangle can be made with these side lengths., I have written this Solution Code: #include<iostream>
using namespace std;
int main(){
int a,b,c,d;
cin >> a >> b >> c >> d;
if((a==c) &&(b==d)){
cout << "Yes\n";
}else if((a==b) && (c==d)){
cout << "Yes\n";
}else if((a==d) && (b==c)){
cout << "Yes\n";
}else{
cout << "No\n";
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Rahul is playing a game in which he has to kill a monster in order to win the game. He has N types of weapons available with him having different attack powers and different weights. Rahul can pick a weapon only if it is not heavier than D.
Given the health of the monster H, the attack powers and weights of weapons, what is the minimum number of weapons required in order to kill the monster?
Note:- A weapon can only be used once.First line of input contains three space separated integers N, D and H.
Second line contains N space separated integers depicting the attack power of each weapon.
Third line of input contains the weight of each weapon.
Constraints:-
1 < = N < = 100000
1 < = D, Weight[i] < = 100000
1 < = H, Power[i] < = 100000000Print the minimum number of weapons required or print -1 if it is impossible to win the game.Sample Input:-
5 5 15
3 8 16 12 6
3 4 10 6 5
Sample Output:-
3
Sample Input:-
5 3 12
3 1 3 6 19
4 5 3 4 8
Sample Output:-
-1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader line = new BufferedReader(new InputStreamReader(System.in));
String[] inputs = line.readLine().split(" ");
int noOFWeapons = Integer.parseInt(inputs[0]);
int weightLimit = Integer.parseInt(inputs[1]);
long monsterHealth = Integer.parseInt(inputs[2]);
String[] powerString = line.readLine().split(" ");
String[] weightString = line.readLine().split(" ");
long[] powerArr = new long[noOFWeapons];
for(int i=0; i<noOFWeapons; i++){
int weight = Integer.parseInt(weightString[i]);
if(weight > weightLimit){
powerArr[i] = 0;
}
else{
powerArr[i] = Integer.parseInt(powerString[i]);
}
}
Arrays.sort(powerArr);
long totalPower = 0l;
long count = 0l;
boolean flag = false;
for(int i=noOFWeapons-1; i>=0; i--){
totalPower += powerArr[i];
count++;
if(totalPower >= monsterHealth){
flag = true;
break;
}
}
System.out.println((flag)? count:"-1");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Rahul is playing a game in which he has to kill a monster in order to win the game. He has N types of weapons available with him having different attack powers and different weights. Rahul can pick a weapon only if it is not heavier than D.
Given the health of the monster H, the attack powers and weights of weapons, what is the minimum number of weapons required in order to kill the monster?
Note:- A weapon can only be used once.First line of input contains three space separated integers N, D and H.
Second line contains N space separated integers depicting the attack power of each weapon.
Third line of input contains the weight of each weapon.
Constraints:-
1 < = N < = 100000
1 < = D, Weight[i] < = 100000
1 < = H, Power[i] < = 100000000Print the minimum number of weapons required or print -1 if it is impossible to win the game.Sample Input:-
5 5 15
3 8 16 12 6
3 4 10 6 5
Sample Output:-
3
Sample Input:-
5 3 12
3 1 3 6 19
4 5 3 4 8
Sample Output:-
-1, I have written this Solution Code: L=list(map(int ,input().rstrip().split(" ")))
n = L[0]
d = L[1]
h = L[2]
arr = list(map(int ,input().rstrip().split(" ")))
L=list(map(int ,input().rstrip().split(" ")))
weapon = []
for i in range(n):
if(L[i]<=d):
weapon.append(arr[i])
weapon = sorted(weapon)
c=0
for i in range(len(weapon)-1,-1,-1):
if(h<=0):
break
else:
h=h-weapon[i]
c=c+1
if(h>0):
print(-1)
else:
print(c), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Rahul is playing a game in which he has to kill a monster in order to win the game. He has N types of weapons available with him having different attack powers and different weights. Rahul can pick a weapon only if it is not heavier than D.
Given the health of the monster H, the attack powers and weights of weapons, what is the minimum number of weapons required in order to kill the monster?
Note:- A weapon can only be used once.First line of input contains three space separated integers N, D and H.
Second line contains N space separated integers depicting the attack power of each weapon.
Third line of input contains the weight of each weapon.
Constraints:-
1 < = N < = 100000
1 < = D, Weight[i] < = 100000
1 < = H, Power[i] < = 100000000Print the minimum number of weapons required or print -1 if it is impossible to win the game.Sample Input:-
5 5 15
3 8 16 12 6
3 4 10 6 5
Sample Output:-
3
Sample Input:-
5 3 12
3 1 3 6 19
4 5 3 4 8
Sample Output:-
-1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define max1 100001
#define MOD 1000000007
#define read(type) readInt<type>()
#define int long long
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
/*
bool check(int A){
int cnt=0;
FOR(i,n){
if(a[i]<=A){cnt++;}
pre[i]=cnt;
}
int ans;
FOR(i,n){
if(a[i]>A){
ans=pre[i];
if(i>d){ans-=pre[i-d-1];}
if(i+d<n){ans+=pre[i+d]-pre[i];}
else{ans+=pre[n-1]-pre[i];}
//out1(A);out(ans);
if(ans*A<a[i]){return false;}
}}
return true;
}
*/
signed main(){
int n,d,h;
cin>>n>>d>>h;
int a[n];
FOR(i,n){cin>>a[i];}
vector<int> v;
int x;
FOR(i,n){
cin>>x;
if(x<=d){v.EB(a[i]);}
}
sort(v.begin(),v.end());
int sum=0;
for(int i=v.size()-1;i>=0;i--){
sum+=v[i];
if(sum>=h){out(v.size()-i);return 0;}
}
out(-1);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Aniket has a binary string of length n. He challenges you to build the lexographically minimum possible string using this string.
In one move you can swap two adjacent characters of the string. You can make at most k swaps.
Note that you can swap the same pair of adjacent characters with indices i and i+1 arbitrary (possibly, zero) number of times. Each such swap is considered a separate move.The first line of the input contains two integers n and k β the length of the string and the number of swaps you can perform.
The second line of the test case contains one string consisting of n characters '0' and '1'.
Constraints
1 <= n <= 1000000
1 <= k <= n*nOutput a single binary string, the answer to the query.Sample Input
8 5
11011010
Sample Output
01011110
Sample Input
7 9
1111100
Sample Output
0101111, I have written this Solution Code: n,k=map(int,input().split())
s=input()
foundZero=False
cntOfOnes=0
ans=""
for i in range(len(s)):
if s[i]=="0":
if cntOfOnes<=k:
ans+="0"
k-=cntOfOnes
else:
ans+="1"*(cntOfOnes-k)
ans+="0"
ans+="1"*k
ans+=s[i+1:]
foundZero=True
break
else:
cntOfOnes+=1
if not foundZero:
ans+="1"*cntOfOnes
print(ans), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Aniket has a binary string of length n. He challenges you to build the lexographically minimum possible string using this string.
In one move you can swap two adjacent characters of the string. You can make at most k swaps.
Note that you can swap the same pair of adjacent characters with indices i and i+1 arbitrary (possibly, zero) number of times. Each such swap is considered a separate move.The first line of the input contains two integers n and k β the length of the string and the number of swaps you can perform.
The second line of the test case contains one string consisting of n characters '0' and '1'.
Constraints
1 <= n <= 1000000
1 <= k <= n*nOutput a single binary string, the answer to the query.Sample Input
8 5
11011010
Sample Output
01011110
Sample Input
7 9
1111100
Sample Output
0101111, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String ss[]=br.readLine().split(" ");
long n=Long.parseLong(ss[0]);
long t=Long.parseLong(ss[1]);
String str = br.readLine();
StringBuilder sb=new StringBuilder(str);
int j=0;
for(int i=0;i<n;i++){
if(sb.charAt(i) == '0'){
int m = (int)Math.min(t,i-j);
t = t-m;
char temp = sb.charAt(i-m);
sb.setCharAt(i-m, sb.charAt(i));
sb.setCharAt(i,temp);
j++;
}
}
System.out.println(sb);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Aniket has a binary string of length n. He challenges you to build the lexographically minimum possible string using this string.
In one move you can swap two adjacent characters of the string. You can make at most k swaps.
Note that you can swap the same pair of adjacent characters with indices i and i+1 arbitrary (possibly, zero) number of times. Each such swap is considered a separate move.The first line of the input contains two integers n and k β the length of the string and the number of swaps you can perform.
The second line of the test case contains one string consisting of n characters '0' and '1'.
Constraints
1 <= n <= 1000000
1 <= k <= n*nOutput a single binary string, the answer to the query.Sample Input
8 5
11011010
Sample Output
01011110
Sample Input
7 9
1111100
Sample Output
0101111, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
#define MOD 1000000007
#define INF 1000000000000000007
#define MAXN 200005
// it's swapnil07 ;)
signed main(){
fast
#ifdef SWAPNIL07
freopen("/home/swapnil/Desktop/c++/input.txt","r",stdin);
freopen("/home/swapnil/Desktop/c++/output.txt","w",stdout);
#endif
int q;
// cin>>q;
q=1;
while(q--){
int n, k; cin>>n>>k;
string s; cin>>s;
vector<int> z;
For(i, 0, n){
if(s[i]=='0')
z.pb(i);
}
For(i, 0, z.size()){
if(z[i] > i){
int need = z[i]-i;
if(k > need){
z[i]=i;
k-=need;
}
else{
z[i]=z[i]-k;
break;
}
}
}
bool ans[n];
memset(ans, true, sizeof(ans));
For(i, 0, z.size()){
ans[z[i]]=false;
}
For(i, 0, n){
cout<<ans[i];
}
cout<<"\n";
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of size N, containing positive integers. You need to sort the elements of array using Insertion sort algorithm.First line of the input denotes number of test cases T. First line of the testcase is the size of array N and second line consists of array elements separated by space.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
Explanation:
Testcase 1: The array after perfoming insertion sort: 1 3 4 7 9.
Testcase 2: The array after performing insertion sort: 1 2 3 4 5 6 7 8 9 10., I have written this Solution Code: // arr is unsorted array
// n is the number of elements in the array
function insertionSort(arr, n) {
// write code here
// do not console.log the answer
// return sorted array
return arr.sort((a, b) => a - b)
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of size N, containing positive integers. You need to sort the elements of array using Insertion sort algorithm.First line of the input denotes number of test cases T. First line of the testcase is the size of array N and second line consists of array elements separated by space.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
Explanation:
Testcase 1: The array after perfoming insertion sort: 1 3 4 7 9.
Testcase 2: The array after performing insertion sort: 1 2 3 4 5 6 7 8 9 10., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void insertionSort(int[] arr){
for(int i = 0; i < arr.length-1; i++){
for(int j = i+1; j < arr.length; j++){
if(arr[i] > arr[j]){
int temp = arr[j];
arr[j] = arr[i];
arr[i] = temp;
}
}
}
}
public static void main (String[] args) {
Scanner scan = new Scanner(System.in);
int T = scan.nextInt();
while(T > 0){
int n = scan.nextInt();
int arr[] = new int[n];
for(int i = 0; i<n; i++){
arr[i] = scan.nextInt();
}
insertionSort(arr);
for(int i = 0; i<n; i++){
System.out.print(arr[i] + " ");
}
System.out.println();
T--;
System.gc();
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of size N, containing positive integers. You need to sort the elements of array using Insertion sort algorithm.First line of the input denotes number of test cases T. First line of the testcase is the size of array N and second line consists of array elements separated by space.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
Explanation:
Testcase 1: The array after perfoming insertion sort: 1 3 4 7 9.
Testcase 2: The array after performing insertion sort: 1 2 3 4 5 6 7 8 9 10., I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N];
signed main() {
IOS;
int t; cin >> t;
while(t--){
int n; cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i];
sort(a + 1, a + n + 1);
for(int i = 1; i <= n; i++)
cout << a[i] << " ";
cout << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of size N, containing positive integers. You need to sort the elements of array using Insertion sort algorithm.First line of the input denotes number of test cases T. First line of the testcase is the size of array N and second line consists of array elements separated by space.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
Explanation:
Testcase 1: The array after perfoming insertion sort: 1 3 4 7 9.
Testcase 2: The array after performing insertion sort: 1 2 3 4 5 6 7 8 9 10., I have written this Solution Code: def InsertionSort(arr):
arr.sort()
return arr, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given any number S ending with 1. What will be the last 2 digits of the resultant number when raised to the power P?The first line of input contains a single integer T denoting the number of test cases. Then T test cases follow. Each test case consists of string S and power P.
Constraints:
1 <= T <= 2*10^3
1 <= |S| <= 60
1 <= P <= 10^6Print the last 2 digit of the resultant. If answer is 1 digit number X, print 0X.Input:
2
1231 213
43591 194
Output:
91
61
Explanation:
Testcase 1: When (1231)^213 is calculated the last 2 digits appeared to be 91., I have written this Solution Code: t = int(input())
while (t):
n, e = map(int, input().split())
d = (((n // 10) % 10) * (e % 10)) % 10
print(d, 1, sep='')
t -= 1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given any number S ending with 1. What will be the last 2 digits of the resultant number when raised to the power P?The first line of input contains a single integer T denoting the number of test cases. Then T test cases follow. Each test case consists of string S and power P.
Constraints:
1 <= T <= 2*10^3
1 <= |S| <= 60
1 <= P <= 10^6Print the last 2 digit of the resultant. If answer is 1 digit number X, print 0X.Input:
2
1231 213
43591 194
Output:
91
61
Explanation:
Testcase 1: When (1231)^213 is calculated the last 2 digits appeared to be 91., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define pu push_back
#define fi first
#define se second
#define mp make_pair
#define int long long
#define pii pair<int,int>
#define mm (s+e)/2
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define sz 200000
signed main()
{
int t;
cin>>t;
while(t>0)
{
t--;
string s;
cin>>s;
int yy;
cin>>yy;
int n=s.size();
if(n==1) {
cout<<"01"<<endl;
continue;
}
int p=s[n-2]-'0';
int q=(p*yy)%10LL;
//if(q==0 ) cout<<1<<endl;
cout<<q<<1<<endl;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, your task is to print all the even integer from 1 to N.<b>User task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the functions <b>For_Loop()</b> that take the integer n as a parameter.
</b>Constraints:</b>
1 <= n <= 100
<b>Note:</b>
<i>But there is a catch here, given user function has already code in it which may or may not be correct, now you need to figure out these and correct them if it is required</i>Print all the even numbers from 1 to n. (print all the numbers in the same line, space-separated)Sample Input:-
5
Sample Output:-
2 4
Sample Input:-
6
Sample Output:-
2 4 6, I have written this Solution Code: def For_Loop(n):
string = ""
for i in range(1, n+1):
if i % 2 == 0:
string += "%s " % i
return string
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, your task is to print all the even integer from 1 to N.<b>User task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the functions <b>For_Loop()</b> that take the integer n as a parameter.
</b>Constraints:</b>
1 <= n <= 100
<b>Note:</b>
<i>But there is a catch here, given user function has already code in it which may or may not be correct, now you need to figure out these and correct them if it is required</i>Print all the even numbers from 1 to n. (print all the numbers in the same line, space-separated)Sample Input:-
5
Sample Output:-
2 4
Sample Input:-
6
Sample Output:-
2 4 6, I have written this Solution Code: public static void For_Loop(int n){
for(int i=2;i<=n;i+=2){
System.out.print(i+" ");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a doubly linked list consisting of N nodes and two integers <b>P</b> and <b>K</b>. Your task is to add an element K at the Pth position from the start of the linked list<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>insertnew()</b>. The description of parameters are mentioned below:
<b>head</b>: head node of the double linked list
<b>K</b>: the element which you have to insert
<b>P</b>: the position at which you have insert
Constraints:
1 <= P <=N <= 1000
1 <=K, Node.data<= 1000
In the sample Input N, P and K are in the order as mentioned below:
<b>N P K</b>Return the head of the modified linked list.Sample Input:-
5 3 2
1 3 2 4 5
Sample Output:-
1 3 2 2 4 5, I have written this Solution Code: public static Node insertnew(Node head, int k,int pos) {
int cnt=1;
if(pos==1){Node temp=new Node(k);
temp.next=head;
head.prev=temp;
return temp;}
Node temp=head;
while(cnt!=pos-1){
temp=temp.next;
cnt++;
}
Node x= new Node(k);
x.next=temp.next;
temp.next.prev=x;
temp.next=x;
x.prev=temp;
return head;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nobita wants to become rich so he came up with an idea, So, he buys some gadgets from the future at a price of C and sells them at a price of S to his friends. Now Nobita wants to know how much he gains by selling all gadget. As we all know Nobita is weak in maths help him to find the profit he getsYou don't have to worry about the input, you just have to complete the function <b>Profit()</b>
<b>Constraints:-</b>
1 <= C <= S <= 1000Print the profit Nobita gets from selling one gadget.Sample Input:-
3 5
Sample Output:-
2
Sample Input:-
9 16
Sample Output:-
7, I have written this Solution Code: def profit(C, S):
print(S - C), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nobita wants to become rich so he came up with an idea, So, he buys some gadgets from the future at a price of C and sells them at a price of S to his friends. Now Nobita wants to know how much he gains by selling all gadget. As we all know Nobita is weak in maths help him to find the profit he getsYou don't have to worry about the input, you just have to complete the function <b>Profit()</b>
<b>Constraints:-</b>
1 <= C <= S <= 1000Print the profit Nobita gets from selling one gadget.Sample Input:-
3 5
Sample Output:-
2
Sample Input:-
9 16
Sample Output:-
7, I have written this Solution Code: static void Profit(int C, int S){
System.out.println(S-C);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is solving a math problem in which she has been given an integer N and her task is to find the number of operations required to convert N into 1.
Where in one operation you replace the number with its second-highest divisor.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>DivisorProblem()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 100000Return the number of operations required.Sample Input:-
100
Sample Output:-
4
Explanation:-
100 - > 50
50 - > 25
25 - > 5
5 - > 1
Sample Input:-
10
Sample Output:-
2, I have written this Solution Code: int DivisorProblem(int N){
int ans=0;
while(N>1){
int cnt=2;
while(N%cnt!=0){
cnt++;
}
N/=cnt;
ans++;
}
return ans;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is solving a math problem in which she has been given an integer N and her task is to find the number of operations required to convert N into 1.
Where in one operation you replace the number with its second-highest divisor.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>DivisorProblem()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 100000Return the number of operations required.Sample Input:-
100
Sample Output:-
4
Explanation:-
100 - > 50
50 - > 25
25 - > 5
5 - > 1
Sample Input:-
10
Sample Output:-
2, I have written this Solution Code: def DivisorProblem(N):
ans=0
while N>1:
cnt=2
while N%cnt!=0:
cnt=cnt+1
N = N//cnt
ans=ans+1
return ans
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is solving a math problem in which she has been given an integer N and her task is to find the number of operations required to convert N into 1.
Where in one operation you replace the number with its second-highest divisor.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>DivisorProblem()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 100000Return the number of operations required.Sample Input:-
100
Sample Output:-
4
Explanation:-
100 - > 50
50 - > 25
25 - > 5
5 - > 1
Sample Input:-
10
Sample Output:-
2, I have written this Solution Code: static int DivisorProblem(int N){
int ans=0;
while(N>1){
int cnt=2;
while(N%cnt!=0){
cnt++;
}
N/=cnt;
ans++;
}
return ans;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is solving a math problem in which she has been given an integer N and her task is to find the number of operations required to convert N into 1.
Where in one operation you replace the number with its second-highest divisor.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>DivisorProblem()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 100000Return the number of operations required.Sample Input:-
100
Sample Output:-
4
Explanation:-
100 - > 50
50 - > 25
25 - > 5
5 - > 1
Sample Input:-
10
Sample Output:-
2, I have written this Solution Code: int DivisorProblem(int N){
int ans=0;
while(N>1){
int cnt=2;
while(N%cnt!=0){
cnt++;
}
N/=cnt;
ans++;
}
return ans;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is building a tower with N disks of sizes 1 to N.
The rules for building the tower are simple:-
*Every day you are provided with one disk having distinct size.
*The disk with larger sizes should be placed at the bottom of the tower.
*The disk with smaller sizes should be placed at the top of the tower.
*You cannot put a new disk on the top of the tower until all the larger disks that are given to you get placed.
Your task is to print N lines denoting the disk sizes that can be put on the tower on the i<sup>th</sup> day.The first line of input contains a single integer N. The next line of input contains N space separated integers depicting the size of the discs.
Constraints:-
1 <= N <= 100000
1 <= Size <= NPrint N lines. In the ith line, print the size of disks that can be placed on the top of the tower in descending order of the disk sizes.
If on the ith day no disks can be placed, then leave that line empty.Sample Input:-
5
4 5 1 2 3
Sample Output:-
5 4
3 2 1
Explanation
On the first day, the disk of size 4 is given. But you cannot put the disk on the bottom of the tower as a disk of size 5 is still remaining.
On the second day, the disk of size 5 will be given so now the disk of sizes 5 and 4 can be placed on the tower.
On the third and fourth days, disks cannot be placed on the tower as the disk of 3 needs to be given yet. Therefore, these lines are empty.
On the fifth day, all the disks of sizes 3, 2, and 1 can be placed on the top of the tower.
Sample Input:-
3
3 2 1
Sample Output:-
3
2
1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main(String args[])throws IOException
{
int n;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
n=Integer.parseInt(br.readLine());
int a[]=new int[n];
StringTokenizer st=new StringTokenizer(br.readLine());
for(int i=0;i<n;i++)
a[i]=Integer.parseInt(st.nextToken());
boolean vis[]=new boolean[n+1];
int max=n;
StringBuilder sb=new StringBuilder();
for(int i=0;i<n;i++)
{
vis[a[i]]=true;
if(vis[max])
{
while(vis[max])
{
sb.append(max).append(" ");
max--;
}
}
sb.append("\n");
}
System.out.println(sb);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is building a tower with N disks of sizes 1 to N.
The rules for building the tower are simple:-
*Every day you are provided with one disk having distinct size.
*The disk with larger sizes should be placed at the bottom of the tower.
*The disk with smaller sizes should be placed at the top of the tower.
*You cannot put a new disk on the top of the tower until all the larger disks that are given to you get placed.
Your task is to print N lines denoting the disk sizes that can be put on the tower on the i<sup>th</sup> day.The first line of input contains a single integer N. The next line of input contains N space separated integers depicting the size of the discs.
Constraints:-
1 <= N <= 100000
1 <= Size <= NPrint N lines. In the ith line, print the size of disks that can be placed on the top of the tower in descending order of the disk sizes.
If on the ith day no disks can be placed, then leave that line empty.Sample Input:-
5
4 5 1 2 3
Sample Output:-
5 4
3 2 1
Explanation
On the first day, the disk of size 4 is given. But you cannot put the disk on the bottom of the tower as a disk of size 5 is still remaining.
On the second day, the disk of size 5 will be given so now the disk of sizes 5 and 4 can be placed on the tower.
On the third and fourth days, disks cannot be placed on the tower as the disk of 3 needs to be given yet. Therefore, these lines are empty.
On the fifth day, all the disks of sizes 3, 2, and 1 can be placed on the top of the tower.
Sample Input:-
3
3 2 1
Sample Output:-
3
2
1, I have written this Solution Code: def Solve(arr):
size = len(arr)
queue = {}
for i in arr:
queue[i] = True
placed = []
if i == size:
placed.append(i)
size -= 1
while size in queue:
placed.append(size)
size -= 1
yield placed
N = int(input())
arr = list(map(int, input().split()))
out_ = Solve(arr)
for i_out_ in out_:
print(' '.join(map(str, i_out_))), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is building a tower with N disks of sizes 1 to N.
The rules for building the tower are simple:-
*Every day you are provided with one disk having distinct size.
*The disk with larger sizes should be placed at the bottom of the tower.
*The disk with smaller sizes should be placed at the top of the tower.
*You cannot put a new disk on the top of the tower until all the larger disks that are given to you get placed.
Your task is to print N lines denoting the disk sizes that can be put on the tower on the i<sup>th</sup> day.The first line of input contains a single integer N. The next line of input contains N space separated integers depicting the size of the discs.
Constraints:-
1 <= N <= 100000
1 <= Size <= NPrint N lines. In the ith line, print the size of disks that can be placed on the top of the tower in descending order of the disk sizes.
If on the ith day no disks can be placed, then leave that line empty.Sample Input:-
5
4 5 1 2 3
Sample Output:-
5 4
3 2 1
Explanation
On the first day, the disk of size 4 is given. But you cannot put the disk on the bottom of the tower as a disk of size 5 is still remaining.
On the second day, the disk of size 5 will be given so now the disk of sizes 5 and 4 can be placed on the tower.
On the third and fourth days, disks cannot be placed on the tower as the disk of 3 needs to be given yet. Therefore, these lines are empty.
On the fifth day, all the disks of sizes 3, 2, and 1 can be placed on the top of the tower.
Sample Input:-
3
3 2 1
Sample Output:-
3
2
1, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
vector<vector<int> > SolveTower (int N, vector<int> a) {
// Write your code here
vector<vector<int> > ans;
int done = N;
priority_queue<int> pq;
for(auto x: a){
pq.push(x);
vector<int> aux;
while(!pq.empty() && pq.top() == done){
aux.push_back(done);
pq.pop();
done--;
}
ans.push_back(aux);
}
sort(a.begin(), a.end());
a.resize(unique(a.begin(), a.end()) - a.begin());
assert(a.size() == N);
return ans;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N;
cin >> N;
assert(1 <= N && N <= 1e6);
vector<int> a(N);
for(int i_a = 0; i_a < N; i_a++)
{
cin >> a[i_a];
}
vector<vector<int> > out_;
out_ = SolveTower(N, a);
for(int i = 0; i < out_.size(); i++){
for(int j = 0; j < out_[i].size(); j++){
cout << out_[i][j] << " ";
}
cout << "\n";
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given any number S ending with 1. What will be the last 2 digits of the resultant number when raised to the power P?The first line of input contains a single integer T denoting the number of test cases. Then T test cases follow. Each test case consists of string S and power P.
Constraints:
1 <= T <= 2*10^3
1 <= |S| <= 60
1 <= P <= 10^6Print the last 2 digit of the resultant. If answer is 1 digit number X, print 0X.Input:
2
1231 213
43591 194
Output:
91
61
Explanation:
Testcase 1: When (1231)^213 is calculated the last 2 digits appeared to be 91., I have written this Solution Code: t = int(input())
while (t):
n, e = map(int, input().split())
d = (((n // 10) % 10) * (e % 10)) % 10
print(d, 1, sep='')
t -= 1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given any number S ending with 1. What will be the last 2 digits of the resultant number when raised to the power P?The first line of input contains a single integer T denoting the number of test cases. Then T test cases follow. Each test case consists of string S and power P.
Constraints:
1 <= T <= 2*10^3
1 <= |S| <= 60
1 <= P <= 10^6Print the last 2 digit of the resultant. If answer is 1 digit number X, print 0X.Input:
2
1231 213
43591 194
Output:
91
61
Explanation:
Testcase 1: When (1231)^213 is calculated the last 2 digits appeared to be 91., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define pu push_back
#define fi first
#define se second
#define mp make_pair
#define int long long
#define pii pair<int,int>
#define mm (s+e)/2
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define sz 200000
signed main()
{
int t;
cin>>t;
while(t>0)
{
t--;
string s;
cin>>s;
int yy;
cin>>yy;
int n=s.size();
if(n==1) {
cout<<"01"<<endl;
continue;
}
int p=s[n-2]-'0';
int q=(p*yy)%10LL;
//if(q==0 ) cout<<1<<endl;
cout<<q<<1<<endl;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N. Print the value of PI with precision upto N decimal places.The only input line contains an integer N.
Constraints:
1 <= N <= 10Print the value of PI.Sample Input 1:
4
Output:
3.1416
Sample Input 2:
10
Output:
3.1415926536, I have written this Solution Code: import java.io.*;
import java.util.Scanner;
class Main {
public static void main (String[] args) {
int n;
Scanner s = new Scanner(System.in);
n = s.nextInt();
if(n==1)System.out.printf("%.1f",Math.PI);
else if(n==2)System.out.printf("%.2f",Math.PI);
else if(n==3)System.out.printf("%.3f",Math.PI);
else if(n==4)System.out.printf("%.4f",Math.PI);
else if(n==5)System.out.printf("%.5f",Math.PI);
else if(n==6)System.out.printf("%.6f",Math.PI);
else if(n==7)System.out.printf("%.7f",Math.PI);
else if(n==8)System.out.printf("%.8f",Math.PI);
else if(n==9)System.out.printf("%.9f",Math.PI);
else System.out.printf("%.10f",Math.PI);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N. Print the value of PI with precision upto N decimal places.The only input line contains an integer N.
Constraints:
1 <= N <= 10Print the value of PI.Sample Input 1:
4
Output:
3.1416
Sample Input 2:
10
Output:
3.1415926536, I have written this Solution Code: n = int(input())
pi = 3.1415926536
print(round(pi, n)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Shinchan and Kazama are standing in a horizontal line, Shinchan is standing at point A and Kazama is standing at point B. Kazama is very intelligent and recently he learned how to calculate the speed if the distance and time are given and now he wants to check if the formula he learned is correct or not So he starts running at a speed of S unit/s towards Shinhan and noted the time he reaches to Shinhan. Since Kazama is disturbed by Shinchan, can you calculate the time for him?The input contains three integers A, B, and S separated by spaces.
Constraints:-
1 <= A, B, V <= 1000
Note:- It is guaranteed that the calculated distance will always be divisible by V.Print the Time taken in seconds by Kazama to reach Shinchan.
Note:- Remember Distance can not be negativeSample Input:-
5 2 3
Sample Output:-
1
Explanation:-
Distance = 5-2 = 3, Speed = 3
Time = Distance/Speed
Sample Input:-
9 1 2
Sample Output:-
4, I have written this Solution Code: a, b, v = map(int, input().strip().split(" "))
c = abs(a-b)
t = c//v
print(t), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Shinchan and Kazama are standing in a horizontal line, Shinchan is standing at point A and Kazama is standing at point B. Kazama is very intelligent and recently he learned how to calculate the speed if the distance and time are given and now he wants to check if the formula he learned is correct or not So he starts running at a speed of S unit/s towards Shinhan and noted the time he reaches to Shinhan. Since Kazama is disturbed by Shinchan, can you calculate the time for him?The input contains three integers A, B, and S separated by spaces.
Constraints:-
1 <= A, B, V <= 1000
Note:- It is guaranteed that the calculated distance will always be divisible by V.Print the Time taken in seconds by Kazama to reach Shinchan.
Note:- Remember Distance can not be negativeSample Input:-
5 2 3
Sample Output:-
1
Explanation:-
Distance = 5-2 = 3, Speed = 3
Time = Distance/Speed
Sample Input:-
9 1 2
Sample Output:-
4, I have written this Solution Code: /* 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 Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
System.out.print(Time(n,m,k));
}
static int Time(int A, int B, int S){
if(B>A){
return (B-A)/S;
}
return (A-B)/S;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number (greater than 2), print two prime numbers whose sum will be equal to given number, else print -1 if no such number exists.
NOTE: A solution will always exist if the number is even. Read Goldbachβs conjecture.
If [a, b] is one solution with a <= b, and [c, d] is another solution with c <= d, and a < c then print [a, b] only
and not all possible solutions.The first line contains an integer T, depicting total number of test cases. Then following T lines contains an integer N.
Constraints:
1 β€ T β€ 100
2 β€ N β€ 1000000Print the two prime numbers in a single line with space in between if exist else print -1.Sample Input:
2
8
3
Sample Output:
3 5
-1, I have written this Solution Code:
// author-Shivam gupta
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1073741824
#define read(type) readInt<type>()
#define max1 1000001
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int li;
typedef unsigned long int uli;
typedef long long int ll;
typedef unsigned long long int ull;
bool isPowerOfTwo (int x)
{
/* First x in the below expression is
for the case when x is 0 */
return x && (!(x&(x-1)));
}
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll power(ll x, ll y, ll p)
{
ll res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
while (y > 0)
{
// If y is odd, multiply x with result
if (y & 1)
res = (res*x) % p;
// y must be even now
y = y>>1; // y = y/2
x = (x*x) % p;
}
return res;
}
// Returns n^(-1) mod p
ll modInverse(ll n, ll p)
{
return power(n, p-2, p);
}
// Returns nCr % p using Fermat's little
// theorem.
ll ncr(ll n, ll r,ll p)
{
// Base case
if (r==0)
return 1;
// Fill factorial array so that we
// can find all factorial of r, n
// and n-r
ll fac[n+1];
fac[0] = 1;
for (ll i=1 ; i<=n; i++)
fac[i] = fac[i-1]*i%p;
return (fac[n]* modInverse(fac[r], p) % p *
modInverse(fac[n-r], p) % p) % p;
}
ll fastexp (ll a, ll b, ll n) {
ll res = 1;
while (b) {
if (b & 1) res = res*a%n;
a = a*a%n;
b >>= 1;
}
return res;
}
bool a[max1];
int main() {
FOR(i,max1){
a[i]=false;}
for(int i=2;i<max1;i++){
if(a[i]==false){
for(int j=i+i;j<max1;j+=i){
a[j]=true;
}
}}
vector<int> v;
map<int,int> m;
for(int i=2;i<max1;i++){
if(a[i]==false){
v.EB(i);
m[i]++;
}
}
int t;
cin>>t;
while(t--){
int n;
cin>>n;
bool win=false;
for(int i=0;i<v.size();i++){
if(m.find(n-v[i])!=m.end()){
if(v[i]>n){break;}
cout<<v[i]<<" "<<n-v[i]<<endl;win=true;break;
}
}
if(win==false){out(-1);}
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number (greater than 2), print two prime numbers whose sum will be equal to given number, else print -1 if no such number exists.
NOTE: A solution will always exist if the number is even. Read Goldbachβs conjecture.
If [a, b] is one solution with a <= b, and [c, d] is another solution with c <= d, and a < c then print [a, b] only
and not all possible solutions.The first line contains an integer T, depicting total number of test cases. Then following T lines contains an integer N.
Constraints:
1 β€ T β€ 100
2 β€ N β€ 1000000Print the two prime numbers in a single line with space in between if exist else print -1.Sample Input:
2
8
3
Sample Output:
3 5
-1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static boolean isPrime(int n)
{
boolean ans=true;
if(n<=1)
{
ans=false;
}
else if(n==2 || n==3)
{
ans=true;
}
else if(n%2==0 || n%3==0)
{
ans=false;
}
else
{
for(int i=5;i*i<=n;i+=6)
{
if(n%i==0 || n%(i+2)==0)
{
ans=false;
break;
}
}
}
return ans;
}
public static void main (String[] args) throws IOException {
BufferedReader scan=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(scan.readLine());
while(t-->0)
{
int n=Integer.parseInt(scan.readLine());
int a=0,b=0;
if(n%2==1)
{
if(isPrime(n-2))
{
a=2;b=n-2;
}
}
else
{
for(int i=2;i<=n/2;i++)
{
if(isPrime(i))
{
if(isPrime(n-i))
{
a=i;b=n-i;
break;
}
}
}
}
if(a!=0 && b!=0)
{
System.out.println(a+" "+b);
}
else
{
System.out.println(-1);
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number (greater than 2), print two prime numbers whose sum will be equal to given number, else print -1 if no such number exists.
NOTE: A solution will always exist if the number is even. Read Goldbachβs conjecture.
If [a, b] is one solution with a <= b, and [c, d] is another solution with c <= d, and a < c then print [a, b] only
and not all possible solutions.The first line contains an integer T, depicting total number of test cases. Then following T lines contains an integer N.
Constraints:
1 β€ T β€ 100
2 β€ N β€ 1000000Print the two prime numbers in a single line with space in between if exist else print -1.Sample Input:
2
8
3
Sample Output:
3 5
-1, I have written this Solution Code: def isprime(num):
if(num==1 or num==0):
return False
for i in range(2,int(num**0.5)+1):
if(num%i==0):
return False
return True
T = int(input())
for test in range(T):
N = int(input())
value = -1
if(N%2==0):
for i in range(2,int(N/2)+1):
if(isprime(i)):
if(isprime(N-i)):
value = i
break
else:
if(isprime(N-2)):
value = 2
if(value==-1):
print(value)
else:
print(str(value)+" "+str(N-value)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, your task is to find the longest subsequence such that the difference between adjacent numbers in the subsequence is equal to 1First line of input contains a single integer N. Next line of input contains N space- separated integers depicting the elements of the array.
Constraints:-
1 <= N <= 1000
1 <= Arr[i] <= 10000Print the length of the longest subsequence.Sample Input:-
5
4 6 1 5 4
Sample Output:-
3
Explanation:-
there are two subsequences of size 3 that fit this criterion:- 4 5 4 and 6 5 4
Sample input:-
8
1 2 3 2 3 7 2 1
Sample Output:-
7, I have written this Solution Code: import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in)) ;
int n = Integer.parseInt(read.readLine()) ;
String[] str = read.readLine().trim().split(" ") ;
int[] arr = new int[n] ;
for(int i=0; i<n; i++) {
arr[i] = Integer.parseInt(str[i]) ;
}
int result = 0 ;
HashMap<Integer,Integer> mp = new HashMap<>() ;
for(int i=0; i<n; i++) {
int len = 0 ;
if(mp.containsKey(arr[i]-1) && mp.get(arr[i]-1) > len) {
len = mp.get(arr[i]-1) ;
}
if(mp.containsKey(arr[i]+1) && mp.get(arr[i]+1) > len) {
len = mp.get(arr[i]+1) ;
}
mp.put(arr[i], len+1) ;
result = Math.max(result, mp.get(arr[i])) ;
}
System.out.println(result);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, your task is to find the longest subsequence such that the difference between adjacent numbers in the subsequence is equal to 1First line of input contains a single integer N. Next line of input contains N space- separated integers depicting the elements of the array.
Constraints:-
1 <= N <= 1000
1 <= Arr[i] <= 10000Print the length of the longest subsequence.Sample Input:-
5
4 6 1 5 4
Sample Output:-
3
Explanation:-
there are two subsequences of size 3 that fit this criterion:- 4 5 4 and 6 5 4
Sample input:-
8
1 2 3 2 3 7 2 1
Sample Output:-
7, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
// Function to find the length of longest subsequence
int longestSubseqWithDiffOne(int arr[], int n)
{
// Initialize the dp[] array with 1 as a
// single element will be of 1 length
int dp[n];
for (int i = 0; i< n; i++)
dp[i] = 1;
// Start traversing the given array
for (int i=1; i<n; i++)
{
// Compare with all the previous elements
for (int j=0; j<i; j++)
{
// If the element is consecutive then
// consider this subsequence and update
// dp[i] if required.
if ((arr[i] == arr[j]+1) ||
(arr[i] == arr[j]-1))
dp[i] = max(dp[i], dp[j]+1);
}
}
// Longest length will be the maximum value
// of dp array.
int result = 1;
for (int i = 0 ; i < n ; i++)
if (result < dp[i])
result = dp[i];
return result;
}
// Driver code
int main()
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
cout<< longestSubseqWithDiffOne(a,n);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number s called rare if all of its digits are divisible by K. Given a number N your task is to check if the given number is rare or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Rare()</b> that takes integer N and K as arguments.
Constraints:-
1 <= N <= 100000
1 <= K <= 9Return 1 if the given number is rare else return 0.Sample Input:-
2468 2
Sample Output:-
1
Sample Input:-
234 2
Sample Output:-
0
Explanation :
3 is not divisible by 2., I have written this Solution Code: class Solution {
public static int Rare(int n, int k){
while(n>0){
if((n%10)%k!=0){
return 0;
}
n/=10;
}
return 1;
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number s called rare if all of its digits are divisible by K. Given a number N your task is to check if the given number is rare or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Rare()</b> that takes integer N and K as arguments.
Constraints:-
1 <= N <= 100000
1 <= K <= 9Return 1 if the given number is rare else return 0.Sample Input:-
2468 2
Sample Output:-
1
Sample Input:-
234 2
Sample Output:-
0
Explanation :
3 is not divisible by 2., I have written this Solution Code: def Rare(N,K):
while N>0:
if(N%10)%K!=0:
return 0
N=N//10
return 1
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number s called rare if all of its digits are divisible by K. Given a number N your task is to check if the given number is rare or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Rare()</b> that takes integer N and K as arguments.
Constraints:-
1 <= N <= 100000
1 <= K <= 9Return 1 if the given number is rare else return 0.Sample Input:-
2468 2
Sample Output:-
1
Sample Input:-
234 2
Sample Output:-
0
Explanation :
3 is not divisible by 2., I have written this Solution Code:
int Rare(int n, int k){
while(n){
if((n%10)%k!=0){
return 0;
}
n/=10;
}
return 1;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number s called rare if all of its digits are divisible by K. Given a number N your task is to check if the given number is rare or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Rare()</b> that takes integer N and K as arguments.
Constraints:-
1 <= N <= 100000
1 <= K <= 9Return 1 if the given number is rare else return 0.Sample Input:-
2468 2
Sample Output:-
1
Sample Input:-
234 2
Sample Output:-
0
Explanation :
3 is not divisible by 2., I have written this Solution Code:
int Rare(int n, int k){
while(n){
if((n%10)%k!=0){
return 0;
}
n/=10;
}
return 1;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a string S of length N consisting of lowercase characters 'a' and 'b'. In one operation, you can select a character and make it equal to one of its adjacent characters. For example, if S = "aab", in one operation you can convert it to any of the following:
1. "aab": By changing the 1<sup>st</sup> character to the 2<sup>nd</sup> character.
2. "aab": By changing the 2<sup>nd</sup> character to the 1<sup>st</sup> character.
3. "abb": By changing the 2<sup>nd</sup> character to the 3<sup>rd</sup> character.
4. "aaa": By changing the 3<sup>rd</sup> character to the 2<sup>nd</sup> character.
Find the minimum number of operations to make all the characters in the string equal.The first line of the input contains a single integer N.
The second line contains a string S of length N consisting of only 'a' and 'b'.
<b> Constraints: </b>
1 β€ N β€ 5000Print the minimum number of operations to make all the characters in the string equal.Sample Input 1:
4
abaa
Sample Output 1:
1
Sample Explanation 1:
You can replace the 'b' at the second position by the 'a' at the first position. Now the string becomes "aaaa".
Sample Input 2:
5
bbbaa
Sample Output 2:
2
, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int c = 0;
String str = br.readLine();
for(int i=0;i<n;i++){
if(str.charAt(i) == 'a'){
c++;
}
}
if((n-c)<c){
System.out.println(n-c);
}else{
System.out.println(c);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a string S of length N consisting of lowercase characters 'a' and 'b'. In one operation, you can select a character and make it equal to one of its adjacent characters. For example, if S = "aab", in one operation you can convert it to any of the following:
1. "aab": By changing the 1<sup>st</sup> character to the 2<sup>nd</sup> character.
2. "aab": By changing the 2<sup>nd</sup> character to the 1<sup>st</sup> character.
3. "abb": By changing the 2<sup>nd</sup> character to the 3<sup>rd</sup> character.
4. "aaa": By changing the 3<sup>rd</sup> character to the 2<sup>nd</sup> character.
Find the minimum number of operations to make all the characters in the string equal.The first line of the input contains a single integer N.
The second line contains a string S of length N consisting of only 'a' and 'b'.
<b> Constraints: </b>
1 β€ N β€ 5000Print the minimum number of operations to make all the characters in the string equal.Sample Input 1:
4
abaa
Sample Output 1:
1
Sample Explanation 1:
You can replace the 'b' at the second position by the 'a' at the first position. Now the string becomes "aaaa".
Sample Input 2:
5
bbbaa
Sample Output 2:
2
, I have written this Solution Code: input()
s = input()
a = s.count("a")
b = s.count("b")
print(a if a<b else b), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a string S of length N consisting of lowercase characters 'a' and 'b'. In one operation, you can select a character and make it equal to one of its adjacent characters. For example, if S = "aab", in one operation you can convert it to any of the following:
1. "aab": By changing the 1<sup>st</sup> character to the 2<sup>nd</sup> character.
2. "aab": By changing the 2<sup>nd</sup> character to the 1<sup>st</sup> character.
3. "abb": By changing the 2<sup>nd</sup> character to the 3<sup>rd</sup> character.
4. "aaa": By changing the 3<sup>rd</sup> character to the 2<sup>nd</sup> character.
Find the minimum number of operations to make all the characters in the string equal.The first line of the input contains a single integer N.
The second line contains a string S of length N consisting of only 'a' and 'b'.
<b> Constraints: </b>
1 β€ N β€ 5000Print the minimum number of operations to make all the characters in the string equal.Sample Input 1:
4
abaa
Sample Output 1:
1
Sample Explanation 1:
You can replace the 'b' at the second position by the 'a' at the first position. Now the string becomes "aaaa".
Sample Input 2:
5
bbbaa
Sample Output 2:
2
, I have written this Solution Code: //Author: Xzirium
//Time and Date: 03:04:29 27 December 2021
//Optional FAST
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
//Required Libraries
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
//Required namespaces
using namespace std;
using namespace __gnu_pbds;
//Required defines
#define endl '\n'
#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)
//Required typedefs
template <typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template <typename T> using ordered_set1 = tree<T,null_type,greater<T>,rb_tree_tag,tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
//Required Constants
const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;
// Required random number generators
// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
//Required Functions
ll power(ll b, ll e)
{
ll r = 1ll;
for(; e > 0; e /= 2, (b *= b) %= MOD)
if(e % 2) (r *= b) %= MOD;
return r;
}
ll modInverse(ll a)
{
return power(a,MOD-2);
}
//Work
int main()
{
#ifndef ONLINE_JUDGE
if (fopen("INPUT.txt", "r"))
{
freopen ("INPUT.txt" , "r" , stdin);
//freopen ("OUTPUT.txt" , "w" , stdout);
}
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
clock_t clk;
clk = clock();
//-----------------------------------------------------------------------------------------------------------//
READV(N);
string S;
cin>>S;
ll a=0,b=0;
FORI(i,0,N)
{
if(S[i]=='a')
{
a++;
}
else
{
b++;
}
}
cout<<min(a,b)<<endl;
//-----------------------------------------------------------------------------------------------------------//
clk = clock() - clk;
cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given the following
- An Array A of size N
- An integer h
Your task is to print number of elements in A that are greater than h. You are given a total of K such tasks.The first line contains N denoting the size of array
The next line contains N space- separated integer denoting the elements of array A.
The next line contains an integer K denoting the number of tasks.
The next line contains an integer h.
<b>Constraints</b>
1 <= N <= 1e5
1 <= A[i] <= 1e9
1 <= K <= 1e5
1 <= h <= 1e9For each task, print the number of elements of A that are greater than h.Sample Input:
5
1 5 3 2 4
1
2
Sample Output :
3, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter wr = new PrintWriter(System.out);
int A_size = Integer.parseInt(br.readLine().trim());
String[] arr_A = br.readLine().trim().split(" ");
int[] A = new int[A_size];
for (int i_A = 0; i_A < arr_A.length; i_A++) {
A[i_A] = Integer.parseInt(arr_A[i_A]);
}
int K_Array_size = Integer.parseInt(br.readLine().trim());
int[] K_Array = new int[K_Array_size];
for (int i_K_Array = 0; i_K_Array < K_Array_size; i_K_Array++) {
K_Array[i_K_Array] = Integer.parseInt(br.readLine().trim());
}
int[] out_ = process_queries(A, K_Array, A_size, K_Array_size);
for (int i_out_ = 0; i_out_ < out_.length; i_out_++) {
wr.println(out_[i_out_]);
}
wr.close();
br.close();
}
static int[] process_queries(int[] A, int[] K_Array, int N, int k) {
int ab[]=new int[k];
Arrays.sort(A);
int h=0;
while(h<k)
{ int f=K_Array[h];int l=0;
int r=N-1;int g=N;
while(l<=r)
{
int m=l+(r-l)/2;
if(A[m]>f)
{
g=m;
r=m-1;
}
else{
l=m+1;
}
}
ab[h]=N-g;
h++;
}
return ab;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given the following
- An Array A of size N
- An integer h
Your task is to print number of elements in A that are greater than h. You are given a total of K such tasks.The first line contains N denoting the size of array
The next line contains N space- separated integer denoting the elements of array A.
The next line contains an integer K denoting the number of tasks.
The next line contains an integer h.
<b>Constraints</b>
1 <= N <= 1e5
1 <= A[i] <= 1e9
1 <= K <= 1e5
1 <= h <= 1e9For each task, print the number of elements of A that are greater than h.Sample Input:
5
1 5 3 2 4
1
2
Sample Output :
3, I have written this Solution Code: /**
* Author : tourist1256
* Time : 2022-01-19 02:44:22
**/
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int k;
cin >> k;
sort(a.begin(), a.end());
for (int i = 0; i < k; i++) {
int temp;
cin >> temp;
auto it = upper_bound(a.begin(), a.end(), temp) - a.begin();
cout << n - it << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice, Bob and Charlie are bidding for an artifact at an auction. Alice bids A rupees, Bob bids B rupees, and Charlie bids C rupees (where A, B, and C are distinct). According to the rules of the auction, the person who bids the highest amount will win the auction. Determine who will win the auction.The first line contains a single integer T β the number of test cases. Then the test cases follow.
The first and only line of each test case contains three integers A, B, and C, β the amount bid by Alice, Bob, and Charlie respectively.
<b>Constraints</b>
1 ≤ T ≤ 1000
1 ≤ A, B, C ≤ 1000
A, B, and C are distinct.For each test case, output who (out of Alice, Bob, and Charlie) will win the auction.Sample Input :
4
200 100 400
155 1000 566
736 234 470
124 67 2
Sample Output :
Charlie
Bob
Alice
Alice
Explanation :
<ul>
<li>Charlie wins the auction since he bid the highest amount. </li>
<li>Bob wins the auction since he bid the highest amount. </li>
<li>Alice wins the auction since she bid the highest amount. </li>
<li>Alice wins the auction since she bid the highest amount. </li>
</ul>, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
int T=sc.nextInt();
for(int i=0;i<T;i++)
{
int a=sc.nextInt();
int b=sc.nextInt();
int c=sc.nextInt();
if(a>b && a>c)
{
System.out.println("Alice");
}
else if(b>a && b>c)
{
System.out.println("Bob");
}
else if(c>a && c>b)
{
System.out.println("Charlie");
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice, Bob and Charlie are bidding for an artifact at an auction. Alice bids A rupees, Bob bids B rupees, and Charlie bids C rupees (where A, B, and C are distinct). According to the rules of the auction, the person who bids the highest amount will win the auction. Determine who will win the auction.The first line contains a single integer T β the number of test cases. Then the test cases follow.
The first and only line of each test case contains three integers A, B, and C, β the amount bid by Alice, Bob, and Charlie respectively.
<b>Constraints</b>
1 ≤ T ≤ 1000
1 ≤ A, B, C ≤ 1000
A, B, and C are distinct.For each test case, output who (out of Alice, Bob, and Charlie) will win the auction.Sample Input :
4
200 100 400
155 1000 566
736 234 470
124 67 2
Sample Output :
Charlie
Bob
Alice
Alice
Explanation :
<ul>
<li>Charlie wins the auction since he bid the highest amount. </li>
<li>Bob wins the auction since he bid the highest amount. </li>
<li>Alice wins the auction since she bid the highest amount. </li>
<li>Alice wins the auction since she bid the highest amount. </li>
</ul>, I have written this Solution Code: #include <bits/stdc++.h>
int main() {
int T = 0;
std::cin >> T;
while (T--) {
int A = 0, B = 0, C = 0;
std::cin >> A >> B >> C;
assert(A != B && B != C && C != A);
if (A > B && A > C) {
std::cout << "Alice" << '\n';
} else if (B > A && B > C) {
std::cout << "Bob" << '\n';
} else {
std::cout << "Charlie" << '\n';
}
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice, Bob and Charlie are bidding for an artifact at an auction. Alice bids A rupees, Bob bids B rupees, and Charlie bids C rupees (where A, B, and C are distinct). According to the rules of the auction, the person who bids the highest amount will win the auction. Determine who will win the auction.The first line contains a single integer T β the number of test cases. Then the test cases follow.
The first and only line of each test case contains three integers A, B, and C, β the amount bid by Alice, Bob, and Charlie respectively.
<b>Constraints</b>
1 ≤ T ≤ 1000
1 ≤ A, B, C ≤ 1000
A, B, and C are distinct.For each test case, output who (out of Alice, Bob, and Charlie) will win the auction.Sample Input :
4
200 100 400
155 1000 566
736 234 470
124 67 2
Sample Output :
Charlie
Bob
Alice
Alice
Explanation :
<ul>
<li>Charlie wins the auction since he bid the highest amount. </li>
<li>Bob wins the auction since he bid the highest amount. </li>
<li>Alice wins the auction since she bid the highest amount. </li>
<li>Alice wins the auction since she bid the highest amount. </li>
</ul>, I have written this Solution Code: T = int(input())
for i in range(T):
A,B,C = list(map(int,input().split()))
if A>B and A>C:
print("Alice")
elif B>A and B>C:
print("Bob")
else:
print("Charlie"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Consider the integer sequence A = {1, 2, 3, ...., N} i.e. the first N natural numbers in order.
You are now given two integers, L and S. Determine whether there exists a subarray with length L and sum S after removing <b>at most one</b> element from A.
A <b>subarray</b> of an array is a non-empty sequence obtained by removing zero or more elements from the front of the array, and zero or more elements from the back of the array.The first line contains a single integer T, the number of test cases.
T lines follow. Each line describes a single test case and contains three integers: N, L, and S.
<b>Constraints:</b>
1 <= T <= 100
2 <= N <= 10<sup>9</sup>
1 <= L <= N-1
1 <= S <= 10<sup>18</sup> <b> (Note that S will not fit in a 32-bit integer) </b>For each testcase, print "YES" (without quotes) if a required subarray can exist, and "NO" (without quotes) otherwise.Sample Input:
3
5 3 11
5 3 5
5 3 6
Sample Output:
YES
NO
YES
Sample Explanation:
For the first test case, we can remove 3 from A to obtain A = {1, 2, 4, 5} where {2, 4, 5} is a required subarray of size 3 and sum 11., I have written this Solution Code: //HEADER FILES AND NAMESPACES
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #include <sys/resource.h>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
// DEFINE STATEMENTS
const long long INF = 1e18;
const int INFINT = INT_MAX/2;
#define num1 1000000007
#define num2 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define REPd(i,a,n) for(ll i=a; i>=n; i--)
#define pb push_back
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define all(x) x.begin(), x.end()
#define M_PI 3.14159265358979323846
#define epsilon (double)(0.000000001)
#define popcount __builtin_popcountll
#define fileio(x, y) freopen(x, "r", stdin); freopen(y, "w", stdout);
#define out(x) cout << ((x) ? "YES\n" : "NO\n")
#define CASE(x, y) cout << "Case #" << x << ":" << " \n"[y]
#define start_clock() auto start_time = std::chrono::high_resolution_clock::now(); auto end_time = start_time;
#define measure() end_time = std::chrono::high_resolution_clock::now(); cerr << (end_time - start_time)/std::chrono::milliseconds(1) << "ms" << endl;
#define reset_clock() start_time = std::chrono::high_resolution_clock::now();
typedef long long ll;
typedef long double ld;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;
typedef vector<pair<long long, long long>> vpll;
typedef vector<int> vii;
// DEBUG FUNCTIONS
#ifdef LOCALY
template<typename T>
void __p(T a) {
cout<<a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
cout<<"{";
__p(a.first);
cout<<",";
__p(a.second);
cout<<"}";
}
template<typename T>
void __p(std::vector<T> a) {
cout<<"{";
for(auto it=a.begin(); it<a.end(); it++)
__p(*it),cout<<",}"[it+1==a.end()];
}
template<typename T>
void __p(std::set<T> a) {
cout<<"{";
for(auto it=a.begin(); it!=a.end();){
__p(*it);
cout<<",}"[++it==a.end()];
}
}
template<typename T>
void __p(std::multiset<T> a) {
cout<<"{";
for(auto it=a.begin(); it!=a.end();){
__p(*it);
cout<<",}"[++it==a.end()];
}
}
template<typename T, typename F>
void __p(std::map<T,F> a) {
cout<<"{\n";
for(auto it=a.begin(); it!=a.end();++it)
{
__p(it->first);
cout << ": ";
__p(it->second);
cout<<"\n";
}
cout << "}\n";
}
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
__p(a1);
__p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
cout<<name<<" : ";
__p(arg1);
cout<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
int bracket=0,i=0;
for(;; i++)
if(names[i]==','&&bracket==0)
break;
else if(names[i]=='(')
bracket++;
else if(names[i]==')')
bracket--;
const char *comma=names+i;
cout.write(names,comma-names)<<" : ";
__p(arg1);
cout<<" | ";
__f(comma+1,args...);
}
#define trace(...) cout<<"Line:"<<__LINE__<<" ", __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...)
#define error(...)
#endif
// DEBUG FUNCTIONS END
// CUSTOM HASH TO SPEED UP UNORDERED MAP AND TO AVOID FORCED CLASHES
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); // FOR RANDOM NUMBER GENERATION
ll mod_exp(ll a, ll b, ll c)
{
ll res=1; a=a%c;
while(b>0)
{
if(b%2==1)
res=(res*a)%c;
b/=2;
a=(a*a)%c;
}
return res;
}
ll norm(ll a,ll b)
{
return (((a = a%b) < 0) ? a + b : a);
}
ll gcdExtended(ll,ll,ll *,ll *);
ll modInverse(ll a, ll m)
{
ll x, y;
ll g = gcdExtended(a, m, &x, &y);
g++; g--; //this line was added just to remove compiler warning
ll res = (x%m + m) % m;
return res;
}
ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
if (a == 0)
{
*x = 0, *y = 1;
return b;
}
ll x1, y1;
ll gcd = gcdExtended(b%a, a, &x1, &y1);
*x = y1 - (b/a) * x1;
*y = x1;
return gcd;
}
struct Graph
{
vector<vector<int>> adj;
Graph(int n): adj(n+1) {}
void add_edge(int a, int b, bool directed = false)
{
adj[a].pb(b);
if(!directed) adj[b].pb(a);
}
};
struct LCA
{
vll tin, tout, level;
vector<vll> up;
ll timer;
void _dfs(vector<vector<int>> &adj, ll x, ll par=-1)
{
up[x][0] = par;
REP(i, 1, 20)
{
if(up[x][i-1] == -1) break;
up[x][i] = up[up[x][i-1]][i-1];
}
tin[x] = ++timer;
for(auto &p: adj[x])
{
if(p != par)
{
level[p] = level[x]+1; _dfs(adj, p, x);
}
}
tout[x] = ++timer;
}
LCA(Graph &G, ll root)
{
int n = G.adj.size();
tin.resize(n); tout.resize(n); up.resize(n, vll(20, -1)); level.resize(n, 0);
timer = 0;
//does not handle forests, easy to modify to handle
_dfs(G.adj, root);
}
ll find_kth(ll x, ll k)
{
ll cur = x;
REP(i, 0, 20)
{
if((k>>i)&1) cur = up[cur][i];
if(cur == -1) break;
}
return cur;
}
bool is_ancestor(ll x, ll y)
{
return tin[x]<=tin[y]&&tout[x]>=tout[y];
}
ll find_lca(ll x, ll y)
{
if(is_ancestor(x, y)) return x;
if(is_ancestor(y, x)) return y;
ll best = x;
REPd(i, 19, 0)
{
if(up[x][i] == -1) continue;
else if(is_ancestor(up[x][i], y)) best = up[x][i];
else x = up[x][i];
}
return best;
}
ll dist(ll a, ll b)
{
return level[a] + level[b] - 2*level[find_lca(a, b)];
}
};
long long ap_sum(long long st, long long len) {
//diff is always 1
long long en = st + len - 1;
return (len * (st + en))/2;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
cin >> t;
for(int i=0; i<t; i++) {
long long N, L, S;
cin >> N >> L >> S;
if(S < ap_sum(1, L) || S > ap_sum(N - L + 1, L)) {
cout << "NO\n";
} else {
cout << "YES\n";
}
}
return 0;
}
/*
*/, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Today is Newton School's first class of this year. Nutan, a student at Newton School, has received his first assignment. He will be given a string as input. His task is to print "Gravity'' if the input is "Apple''; otherwise, he will have to print "Space''.
Can you help Nutan in solving his first assignment? Note that the quotation marks are just for clarity. They are not part of the input string, and should not be a part of your output string.The input consists of a single line that contains a string S (1 ≤ length of S ≤ 10). The string only consists of lowercase and uppercase letters.Print "Gravity'' or "Space'' according to the input.Sample Input 1:
Apple
Sample Output 1:
Gravity
Sample Input 2:
Mango
Sample Output 2:
Space
Sample Input 3:
AppLE
Sample Output 3:
Space, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main (String[] args) {
FastReader sc= new FastReader();
String str= sc.nextLine();
String a="Apple";
if(a.equals(str)){
System.out.println("Gravity");
}
else{
System.out.println("Space");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Today is Newton School's first class of this year. Nutan, a student at Newton School, has received his first assignment. He will be given a string as input. His task is to print "Gravity'' if the input is "Apple''; otherwise, he will have to print "Space''.
Can you help Nutan in solving his first assignment? Note that the quotation marks are just for clarity. They are not part of the input string, and should not be a part of your output string.The input consists of a single line that contains a string S (1 ≤ length of S ≤ 10). The string only consists of lowercase and uppercase letters.Print "Gravity'' or "Space'' according to the input.Sample Input 1:
Apple
Sample Output 1:
Gravity
Sample Input 2:
Mango
Sample Output 2:
Space
Sample Input 3:
AppLE
Sample Output 3:
Space, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
//Work
int main()
{
#ifndef ONLINE_JUDGE
if (fopen("INPUT.txt", "r"))
{
freopen ("INPUT.txt" , "r" , stdin);
//freopen ("OUTPUT.txt" , "w" , stdout);
}
#endif
//-----------------------------------------------------------------------------------------------------------//
string S;
cin>>S;
if(S=="Apple")
{
cout<<"Gravity"<<endl;
}
else
{
cout<<"Space"<<endl;
}
//-----------------------------------------------------------------------------------------------------------//
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Today is Newton School's first class of this year. Nutan, a student at Newton School, has received his first assignment. He will be given a string as input. His task is to print "Gravity'' if the input is "Apple''; otherwise, he will have to print "Space''.
Can you help Nutan in solving his first assignment? Note that the quotation marks are just for clarity. They are not part of the input string, and should not be a part of your output string.The input consists of a single line that contains a string S (1 ≤ length of S ≤ 10). The string only consists of lowercase and uppercase letters.Print "Gravity'' or "Space'' according to the input.Sample Input 1:
Apple
Sample Output 1:
Gravity
Sample Input 2:
Mango
Sample Output 2:
Space
Sample Input 3:
AppLE
Sample Output 3:
Space, I have written this Solution Code: n=input()
if n=='Apple':print('Gravity')
else:print('Space'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the number of the month, your task is to calculate the number of days present in the particular month.
<b>Note:-</b>
Consider non-leap yearUser task:
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>numberofdays()</b> which contains M as a parameter.
<b>Constraints:-</b>
1 <= M <= 12Print the number of days in the particular month.Sample Input 1:-
1
Sample Output 1:
31
Sample Input 2:-
2
Sample Output 2:-
28, I have written this Solution Code: function numberOfDays(n)
{
let ans;
switch(n)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
ans = Number(31);
break;
case 2:
ans = Number(28);
break;
default:
ans = Number(30);
break;
}
return ans;
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the number of the month, your task is to calculate the number of days present in the particular month.
<b>Note:-</b>
Consider non-leap yearUser task:
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>numberofdays()</b> which contains M as a parameter.
<b>Constraints:-</b>
1 <= M <= 12Print the number of days in the particular month.Sample Input 1:-
1
Sample Output 1:
31
Sample Input 2:-
2
Sample Output 2:-
28, I have written this Solution Code:
static void numberofdays(int M){
if(M==4 || M ==6 || M==9 || M==11){System.out.print(30);}
else if(M==2){System.out.print(28);}
else{
System.out.print(31);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers a and b, your task is to check following conditions:-
1. If a <= 10 and b >= 10 (Logical AND).
2. Atleast one from a or b will be even (Logical OR).
3. if a is not equal to b (Logical NOT).The first line of the input contains 2 integers a and b.
<b>Constraints:</b>
1 <= a, b <= 100Print the string <b>"true"</b> if the condition holds in each function else <b>"false"</b> .
Sample Input:-
3 12
Sample Output:-
true true true
Explanation
So a = 3 and b = 12, so a<=10 and b>=10 hence first condition true, a is not even but b is even so atleast one of them is even hence true, third a != b which is also true hence the final output comes true true true.
Sample Input:-
10 10
Sample Output:-
true true false
, I have written this Solution Code: a, b = list(map(int, input().split(" ")))
print(str(a <= 10 and b >= 10).lower(), end=' ')
print(str(a % 2 == 0 or b % 2 == 0).lower(), end=' ')
print(str(not a == b).lower()), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers a and b, your task is to check following conditions:-
1. If a <= 10 and b >= 10 (Logical AND).
2. Atleast one from a or b will be even (Logical OR).
3. if a is not equal to b (Logical NOT).The first line of the input contains 2 integers a and b.
<b>Constraints:</b>
1 <= a, b <= 100Print the string <b>"true"</b> if the condition holds in each function else <b>"false"</b> .
Sample Input:-
3 12
Sample Output:-
true true true
Explanation
So a = 3 and b = 12, so a<=10 and b>=10 hence first condition true, a is not even but b is even so atleast one of them is even hence true, third a != b which is also true hence the final output comes true true true.
Sample Input:-
10 10
Sample Output:-
true true false
, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
class Main {
static boolean Logical_AND(int a, int b){
if(a<=10 && b>=10){
return true;}
return false;}
static boolean Logical_OR(int a, int b){
if(a%2==0 || b%2==0){
return true;}
return false;}
static boolean Logical_NOT(int a, int b){
if(a!=b){
return true;}
return false;}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a=in.nextInt();
int b=in.nextInt();
System.out.print(Logical_AND(a, b)+" ");
System.out.print(Logical_OR(a,b)+" ");
System.out.print(Logical_NOT(a,b)+" ");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code: static void pattern(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
System.out.print(j + " ");
}
System.out.println();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code:
void patternPrinting(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
printf("%d ",j);
}
printf("\n");
}
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code: function pattern(n) {
// write code herenum
for(let i = 1;i<=n;i++){
let str = ''
for(let k = 1; k <= i;k++){
if(k === 1) {
str += `${k}`
}else{
str += ` ${k}`
}
}
console.log(str)
}
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code:
void patternPrinting(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
printf("%d ",j);
}
printf("\n");
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code: def patternPrinting(n):
for i in range(1,n+1):
for j in range (1,i+1):
print(j,end=' ')
print()
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array <b>A</b> of size N, and an integer x = 0. In one move, you can choose two indices i and j such that i < j and add the maximum of these integers from the two to x. And finally, delete that bigger number from the array. If both elements are equal you can remove any of the two and add that value to x.
After performing this operation a maximum of K times, find the maximum possible value of x you can get.First line of the input contains two integers, N and K.
The second line of the input contains N space seperated integers.
Constraints:
1 <= K < N <= 10<sup>5</sup>
1 <= A<sub>i</sub> <= 10<sup>9</sup>Print the maximum possible value of x you can get.Sample Input:
5 2
5 6 4 2 3
Sample Output:
11
Explanation:
In the first move, we choose i = 1 and j = 3. We get the max value of these as 5, and then we add it to x and remove it from the array. x = 5, A = [6, 4, 2, 3]
In the next and final move, we again choose indices i = 1, j = 3. Updated x = 11, A = [4, 2, 3], I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
try{
BufferedReader b = new BufferedReader(new InputStreamReader(System.in));
String []s=b.readLine().split(" ");
int n = Integer.parseInt(s[0]);
int [] a=new int[n];
int k = Integer.parseInt(s[1]);
String []str = b.readLine().split(" ");
for(int i=0;i<n;i++){
a[i]=Integer.parseInt(str[i]);
}
Arrays.sort(a);
long x=0;
int j=a.length-1;
for(int i=0;i<k;i++){
x+=a[j--];
}
System.out.print(x);
}
catch(Exception e){return;}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array <b>A</b> of size N, and an integer x = 0. In one move, you can choose two indices i and j such that i < j and add the maximum of these integers from the two to x. And finally, delete that bigger number from the array. If both elements are equal you can remove any of the two and add that value to x.
After performing this operation a maximum of K times, find the maximum possible value of x you can get.First line of the input contains two integers, N and K.
The second line of the input contains N space seperated integers.
Constraints:
1 <= K < N <= 10<sup>5</sup>
1 <= A<sub>i</sub> <= 10<sup>9</sup>Print the maximum possible value of x you can get.Sample Input:
5 2
5 6 4 2 3
Sample Output:
11
Explanation:
In the first move, we choose i = 1 and j = 3. We get the max value of these as 5, and then we add it to x and remove it from the array. x = 5, A = [6, 4, 2, 3]
In the next and final move, we again choose indices i = 1, j = 3. Updated x = 11, A = [4, 2, 3], I have written this Solution Code: N,K = map(int,input().split())
arr = list(map(int,input().split()))
soArr = sorted(arr)
sum1 = 0
for i in range(1,K+1):
sum1 += soArr[-i]
print(sum1), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array <b>A</b> of size N, and an integer x = 0. In one move, you can choose two indices i and j such that i < j and add the maximum of these integers from the two to x. And finally, delete that bigger number from the array. If both elements are equal you can remove any of the two and add that value to x.
After performing this operation a maximum of K times, find the maximum possible value of x you can get.First line of the input contains two integers, N and K.
The second line of the input contains N space seperated integers.
Constraints:
1 <= K < N <= 10<sup>5</sup>
1 <= A<sub>i</sub> <= 10<sup>9</sup>Print the maximum possible value of x you can get.Sample Input:
5 2
5 6 4 2 3
Sample Output:
11
Explanation:
In the first move, we choose i = 1 and j = 3. We get the max value of these as 5, and then we add it to x and remove it from the array. x = 5, A = [6, 4, 2, 3]
In the next and final move, we again choose indices i = 1, j = 3. Updated x = 11, A = [4, 2, 3], I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int long long
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using T = pair<int, int>;
typedef long double ld;
const int mod = 1e9 + 7;
const int INF = 2e9;
void solve(){
int n, k;
cin >> n >> k;
vector<int> a(n);
for(auto &i : a) cin >> i;
sort(rall(a));
int sum = 0;
for(int i = 0; i < k; i++){
sum += a[i];
}
cout << sum;
}
signed main(){
fast
int t = 1;
// cin >> t;
for(int i = 1; i <= t; i++){
solve();
if(i != t) cout << endl;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, if the year is a multiple of 100 and not a multiple of 400, then it is not a leap year.<b>User Task:</b>
Complete the function <b>LeapYear()</b> that takes integer n as a parameter.
<b>Constraint:</b>
1 <= n <= 5000If it is a leap year then print <b>YES</b> and if it is not a leap year, then print <b>NO</b>Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code: n = int(input())
if (n%4==0 and n%100!=0 or n%400==0):
print("YES")
elif n==0:
print("YES")
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, if the year is a multiple of 100 and not a multiple of 400, then it is not a leap year.<b>User Task:</b>
Complete the function <b>LeapYear()</b> that takes integer n as a parameter.
<b>Constraint:</b>
1 <= n <= 5000If it is a leap year then print <b>YES</b> and if it is not a leap year, then print <b>NO</b>Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code:
import java.util.Scanner;
class Main {
public static void main (String[] args)
{
//Capture the user's input
Scanner scanner = new Scanner(System.in);
//Storing the captured value in a variable
int n = scanner.nextInt();
LeapYear(n);
}
static void LeapYear(int year){
if(year%400==0 || (year%100 != 0 && year%4==0)){System.out.println("YES");}
else {
System.out.println("NO");}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers a and b, your task is to check following conditions:-
1. If a <= 10 and b >= 10 (Logical AND).
2. Atleast one from a or b will be even (Logical OR).
3. if a is not equal to b (Logical NOT).The first line of the input contains 2 integers a and b.
<b>Constraints:</b>
1 <= a, b <= 100Print the string <b>"true"</b> if the condition holds in each function else <b>"false"</b> .
Sample Input:-
3 12
Sample Output:-
true true true
Explanation
So a = 3 and b = 12, so a<=10 and b>=10 hence first condition true, a is not even but b is even so atleast one of them is even hence true, third a != b which is also true hence the final output comes true true true.
Sample Input:-
10 10
Sample Output:-
true true false
, I have written this Solution Code: a, b = list(map(int, input().split(" ")))
print(str(a <= 10 and b >= 10).lower(), end=' ')
print(str(a % 2 == 0 or b % 2 == 0).lower(), end=' ')
print(str(not a == b).lower()), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers a and b, your task is to check following conditions:-
1. If a <= 10 and b >= 10 (Logical AND).
2. Atleast one from a or b will be even (Logical OR).
3. if a is not equal to b (Logical NOT).The first line of the input contains 2 integers a and b.
<b>Constraints:</b>
1 <= a, b <= 100Print the string <b>"true"</b> if the condition holds in each function else <b>"false"</b> .
Sample Input:-
3 12
Sample Output:-
true true true
Explanation
So a = 3 and b = 12, so a<=10 and b>=10 hence first condition true, a is not even but b is even so atleast one of them is even hence true, third a != b which is also true hence the final output comes true true true.
Sample Input:-
10 10
Sample Output:-
true true false
, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
class Main {
static boolean Logical_AND(int a, int b){
if(a<=10 && b>=10){
return true;}
return false;}
static boolean Logical_OR(int a, int b){
if(a%2==0 || b%2==0){
return true;}
return false;}
static boolean Logical_NOT(int a, int b){
if(a!=b){
return true;}
return false;}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a=in.nextInt();
int b=in.nextInt();
System.out.print(Logical_AND(a, b)+" ");
System.out.print(Logical_OR(a,b)+" ");
System.out.print(Logical_NOT(a,b)+" ");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an unsorted array, your task is to sort the array using merge sort.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>implementMergeSort()</b> that takes 3 arguments.
arr: input array
start: starting index which is 0
end: ending index of array
Constraints
1 <= T <= 100
1 <= N <= 10<sup>6</sup>
0 <= Arr[i] <= 10<sup>9</sup>
Sum of 'N' over all test cases does not exceed 10<sup>6</sup>You need to return the sorted array. The driver code will print the array in sorted form.Sample Input:
2
3
3 1 2
3
4 5 6
Sample Output:
1 2 3
4 5 6, I have written this Solution Code:
public static int[] implementMergeSort(int arr[], int start, int end)
{
if (start < end)
{
// Find the middle point
int mid = (start+end)/2;
// Sort first and second halves
implementMergeSort(arr, start, mid);
implementMergeSort(arr , mid+1, end);
// Merge the sorted halves
merge(arr, start, mid, end);
}
return arr;
}
public static void merge(int arr[], int start, int mid, int end)
{
// Find sizes of two subarrays to be merged
int n1 = mid - start + 1;
int n2 = end - mid;
/* Create temp arrays */
int L[] = new int [n1];
int R[] = new int [n2];
/*Copy data to temp arrays*/
for (int i=0; i<n1; ++i)
L[i] = arr[start + i];
for (int j=0; j<n2; ++j)
R[j] = arr[mid + 1+ j];
/* Merge the temp arrays */
// Initial indexes of first and second subarrays
int i = 0, j = 0;
// Initial index of merged subarry array
int k = start;
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
{
arr[k] = L[i];
i++;
}
else
{
arr[k] = R[j];
j++;
}
k++;
}
/* Copy remaining elements of L[] if any */
while (i < n1)
{
arr[k] = L[i];
i++;
k++;
}
/* Copy remaining elements of R[] if any */
while (j < n2)
{
arr[k] = R[j];
j++;
k++;
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an unsorted array, your task is to sort the array using merge sort.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>implementMergeSort()</b> that takes 3 arguments.
arr: input array
start: starting index which is 0
end: ending index of array
Constraints
1 <= T <= 100
1 <= N <= 10<sup>6</sup>
0 <= Arr[i] <= 10<sup>9</sup>
Sum of 'N' over all test cases does not exceed 10<sup>6</sup>You need to return the sorted array. The driver code will print the array in sorted form.Sample Input:
2
3
3 1 2
3
4 5 6
Sample Output:
1 2 3
4 5 6, I have written this Solution Code: for _ in range(int(input())):
n = int(input())
print(*sorted(list(map(int,input().split())))), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code: static void pattern(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
System.out.print(j + " ");
}
System.out.println();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code:
void patternPrinting(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
printf("%d ",j);
}
printf("\n");
}
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code: function pattern(n) {
// write code herenum
for(let i = 1;i<=n;i++){
let str = ''
for(let k = 1; k <= i;k++){
if(k === 1) {
str += `${k}`
}else{
str += ` ${k}`
}
}
console.log(str)
}
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code:
void patternPrinting(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
printf("%d ",j);
}
printf("\n");
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code: def patternPrinting(n):
for i in range(1,n+1):
for j in range (1,i+1):
print(j,end=' ')
print()
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Now let us create a table to store the post created by various users. Create a table POST with the following fields (ID INT, USERNAME VARCHAR(24), POST_TITLE VARCHAR(72), POST_DESCRIPTION TEXT, DATETIME_CREATED DATETIME, NUMBER_OF_LIKES INT, PHOTO BLOB)
( USE ONLY UPPERCASE LETTERS )
<schema>[{'name': 'POST', 'columns': [{'name': 'ID', 'type': 'INT'}, {'name': 'USERNAME', 'type': 'VARCHAR(24)'}, {'name': 'POST_TITLE', 'type': 'VARCHAR (72)'}, {'name': 'POST_DESCRIPTION', 'type': 'TEXT'}, {'name': 'DATETIME_CREATED', 'type': 'TEXT'}, {'name': 'NUMBER_OF_LIKES', 'type': 'INT'}, {'name': 'PHOTO', 'type': 'BLOB'}]}]</schema>nannannan, I have written this Solution Code: CREATE TABLE POST(
ID INT,
USERNAME VARCHAR(24),
POST_TITLE VARCHAR(72),
POST_DESCRIPTION TEXT,
DATETIME_CREATED TEXT,
NUMBER_OF_LIKES INT,
PHOTO BLOB
);, In this Programming Language: SQL, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Complete the Main class. Implement the getArea() and getPerimeter() methods for the child classes Parallelogram, Rhombus, Rectangle, and Square having Abstract class Quadrilateral as a parent class.
Do not change the name of any classThe first line of input contains side1, side2 and height of the parallelogram
The second line of input contains side and height of rhombus
The third line of input contains length and height of the rectangle
The fourth line of input contains side of square
If the length of any side or height for any shape is negative, then print <b><i>Length of a side cannot be negative. Please Enter a positive integer.</b></i>"Perimeter of Parallelogram is " + parallelogram.getPerimeter() +" and Area of Parallelogram is " + parallelogram.getArea()
"Perimeter of Rhombus is " + rhombus.getPerimeter() +" and Area of Rhombus is " + rhombus.getArea()
"Perimeter of Rectangle is " + rectangle.getPerimeter() +" and Area of Rectangle is " + rectangle.getArea()
"Perimeter of Square is " + square.getPerimeter()+ " and Area of Square is " + square.getArea()
Sample Input 1:
1.0 2.0 3.0
7.0 5.0
4.0 2.0
6.0
Sample Output 2:
Perimeter of Parallelogram is 6.0 and Area of Parallelogram is 3.0
Perimeter of Rhombus is 28.0 and Area of Rhombus is 35.0
Perimeter of Rectangle is 12.0 and Area of Rectangle is 8.0
Perimeter of Square is 24.0 and Area of Square is 36.0
Sample Input 2:
3.0 9.0 7.0
6.0 4.0
-1.0 5.0
8.0
Sample Output 2:
Length of a side cannot be negative. Please Enter a positive integer
, I have written this Solution Code: from abc import ABC, abstractmethod
class Quadrilateral(ABC):
def __init__(self, side1, side2, side3, side4):
self.side1, self.side2, self.side3, self.side4 = side1, side2, side3, side4
@abstractmethod
def getArea(self):
pass
def getPerimeter(self):
return (self.side1+self.side2+self.side3+self.side4)
class Parallelogram(Quadrilateral):
def __init__(self, side1, side2, height):
super().__init__(side1, side2, side1, side2)
self.heightPerpendicularToSide1 = height
def getArea(self):
return self.side1*self.heightPerpendicularToSide1
class Rhombus(Parallelogram):
def __init__(self, side, height):
super().__init__(side, side, height)
class Rectangle(Parallelogram):
def __init__(self, length, breadth):
super().__init__(length, breadth, breadth)
class Square(Rhombus):
def __init__(self, side):
super().__init__(side, side)
def main():
# Parallelogram
side1, side2, height = map(float, input().split())
# side1 = float(input())
# side2 = float(input())
# height = float(input())
parallelogram = Parallelogram(side1, side2, height)
# Rhombus
side, heightOfRhombus = map(float, input().split())
# side = float(input())
# heightOfRhombus = float(input())
rhombus = Rhombus(side, heightOfRhombus)
# Rectangle
length, breadth = map(float, input().split())
# length = float(input())
# breadth = float(input())
rectangle = Rectangle(length, breadth)
# Square
sideOfSquare = float(input())
square = Square(sideOfSquare)
if(side1 < 0 or side2 < 0 or heightOfRhombus < 0 or height < 0 or side < 0 or length < 0 or breadth < 0 or sideOfSquare < 0):
print("Length of a side cannot be negative. Please Enter a positive integer")
return
print("Perimeter of Parallelogram is",
parallelogram.getPerimeter(), "and Area of Parallelogram is", parallelogram.getArea())
print("Perimeter of Rhombus is",
rhombus.getPerimeter(), "and Area of Rhombus is", rhombus.getArea())
print("Perimeter of Rectangle is",
rectangle.getPerimeter(), "and Area of Rectangle is", rectangle.getArea())
print("Perimeter of Square is",
square.getPerimeter(), "and Area of Square is", square.getArea())
if __name__ == "__main__":
main()
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Complete the Main class. Implement the getArea() and getPerimeter() methods for the child classes Parallelogram, Rhombus, Rectangle, and Square having Abstract class Quadrilateral as a parent class.
Do not change the name of any classThe first line of input contains side1, side2 and height of the parallelogram
The second line of input contains side and height of rhombus
The third line of input contains length and height of the rectangle
The fourth line of input contains side of square
If the length of any side or height for any shape is negative, then print <b><i>Length of a side cannot be negative. Please Enter a positive integer.</b></i>"Perimeter of Parallelogram is " + parallelogram.getPerimeter() +" and Area of Parallelogram is " + parallelogram.getArea()
"Perimeter of Rhombus is " + rhombus.getPerimeter() +" and Area of Rhombus is " + rhombus.getArea()
"Perimeter of Rectangle is " + rectangle.getPerimeter() +" and Area of Rectangle is " + rectangle.getArea()
"Perimeter of Square is " + square.getPerimeter()+ " and Area of Square is " + square.getArea()
Sample Input 1:
1.0 2.0 3.0
7.0 5.0
4.0 2.0
6.0
Sample Output 2:
Perimeter of Parallelogram is 6.0 and Area of Parallelogram is 3.0
Perimeter of Rhombus is 28.0 and Area of Rhombus is 35.0
Perimeter of Rectangle is 12.0 and Area of Rectangle is 8.0
Perimeter of Square is 24.0 and Area of Square is 36.0
Sample Input 2:
3.0 9.0 7.0
6.0 4.0
-1.0 5.0
8.0
Sample Output 2:
Length of a side cannot be negative. Please Enter a positive integer
, I have written this Solution Code: //Do not change the name of the class
import java.util.*;
// Do not edit the Quadrilateral class
abstract class Quadrilateral {
double side1;
double side2;
double side3;
double side4;
public Quadrilateral(double side1, double side2, double side3, double side4) {
this.side1 = side1;
this.side2 = side2;
this.side3 = side3;
this.side4 = side4;
}
protected abstract double getArea();
protected double getPerimeter() {
return (side1+side2+side3+side4);
}
}
class Parallelogram extends Quadrilateral {
double heightPerpendicularToSide1;
public Parallelogram(double side1, double side2, double height) {
super(side1, side2, side1, side2);
this.heightPerpendicularToSide1 = height;
}
public double getArea() {
return side1*heightPerpendicularToSide1;
}
}
class Rhombus extends Parallelogram {
public Rhombus(double side, double height) {
super(side, side, height);
}
}
class Rectangle extends Parallelogram {
public Rectangle(double length, double breadth) {
super(length, breadth, breadth);
}
}
class Square extends Rhombus {
public Square(double side) {
super(side, side);
}
}
// Do not edit the Main class
class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
//Parallelogram
double side1 = scan.nextDouble();
double side2 = scan.nextDouble();
double height = scan.nextDouble();
Parallelogram parallelogram = new Parallelogram(side1, side2, height);
//Rhombus
double side = scan.nextDouble();
double heightOfRhombus = scan.nextDouble();
Rhombus rhombus = new Rhombus(side, heightOfRhombus);
//Rectangle
double length = scan.nextDouble();
double breadth = scan.nextDouble();
Rectangle rectangle = new Rectangle(length, breadth);
//Square
double sideOfSquare = scan.nextDouble();
Square square = new Square(sideOfSquare);
if(side1<0 || side2<0 || heightOfRhombus<0 || height<0 || side<0 || length<0 || breadth<0 || sideOfSquare<0){
System.out.println("Length of a side cannot be negative. Please Enter a positive integer");
return;
}
System.out.println("Perimeter of Parallelogram is " + parallelogram.getPerimeter() +" and Area of Parallelogram is " + parallelogram.getArea());
System.out.println("Perimeter of Rhombus is " + rhombus.getPerimeter() +" and Area of Rhombus is " + rhombus.getArea());
System.out.println("Perimeter of Rectangle is " + rectangle.getPerimeter() +" and Area of Rectangle is " + rectangle.getArea());
System.out.println("Perimeter of Square is " + square.getPerimeter()+ " and Area of Square is " + square.getArea());
scan.close();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers a and b, your task is to calculate values for each of the following operations:-
a + b
a - b
a * b
a/bSince this will be a functional problem, you don't have to take input. You have to complete the function
<b>operations()</b> that takes the integer a and b as parameters.
<b>Constraints:</b>
1 ≤ b ≤ a ≤1000
<b> It is guaranteed that a will be divisible by b.</b>Print the mentioned operations each in a new line.Sample Input:
15 3
Sample Output:
18
12
45
5, I have written this Solution Code: def operations(x, y):
print(x+y)
print(x-y)
print(x*y)
print(x//y), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are fighting against a monster.
The monster has health M while you have initial health Y.
To defeat him, you need health strictly greater than the monster's health.
You have access to two types of pills, red and green. Eating a red pill adds R to your health while eating a green pill multiplies your health by G.
Determine if it is possible to defeat the monster by eating at most one pill of any kind.Input contains four integers M (0 <= M <= 10<sup>4</sup>), Y (0 <= Y <= 10<sup>4</sup>), R (0 <= R <= 10<sup>4</sup>) and G (1 <= G <= 10<sup>4</sup>).Print 1 if it is possible to defeat the monster and 0 if it is impossible to defeat it.Sample Input 1:
10 2 2 2
Sample Output 1:
0
Sample Input 2:
8 7 2 1
Sample Output 2:
1
Explanation for Sample 2:
You can eat a red pill to make your health : 7 + 2 = 9 > 8., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException
{
InputStreamReader pk = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(pk);
String[] strNums;
int num[] = new int[4];
strNums = in.readLine().split(" ");
for (int i = 0; i < strNums.length; i++) {
num[i] = Integer.parseInt(strNums[i]);
}
if((num[0]<(num[1]+num[2])) || (num[0]<(num[1]*num[3])))
System.out.println("1");
else
System.out.println("0");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.