Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: Given an integer array A of N integers, find the pair of integers in the array which have minimum XOR value. Report the minimum XOR value.First line denotes N, the size of the array.
Next line denotes N space-separated array elements.
Constraints:
2 <= N <= 100000
0 <= A[i] <= 10^7Print a single integer denoting minimum xor valueSample Input
4
0 2 5 7
Sample Output
2
Explanation:
0 xor 2 = 2
Sample Input
4
0 4 7 9
Sample Output
3, I have written this Solution Code: a=int(input())
lis = list(map(int,input().split()))
val=666666789
for i in range(a+1):
for j in range(i+1,a):
temp = lis[i]^lis[j]
if(temp<val):
val = temp
if(val==0):
break
print(val), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer array A of N integers, find the pair of integers in the array which have minimum XOR value. Report the minimum XOR value.First line denotes N, the size of the array.
Next line denotes N space-separated array elements.
Constraints:
2 <= N <= 100000
0 <= A[i] <= 10^7Print a single integer denoting minimum xor valueSample Input
4
0 2 5 7
Sample Output
2
Explanation:
0 xor 2 = 2
Sample Input
4
0 4 7 9
Sample Output
3, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
// Function to find minimum XOR pair
int minXOR(int arr[], int n)
{
// Sort given array
sort(arr, arr + n);
int minXor = INT_MAX;
int val = 0;
// calculate min xor of consecutive pairs
for (int i = 0; i < n - 1; i++) {
val = arr[i] ^ arr[i + 1];
minXor = min(minXor, val);
}
return minXor;
}
// Driver program
int main()
{
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
cout << minXOR(arr, n) << endl;
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division.
As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget.
You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q.
Constraints:-
0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined.
Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:-
9 3
Sample Output:-
3
Sample Input:-
8 5
Sample Output:-
1
Explanation:-
8/5 = 1.6 = 1(floor), I have written this Solution Code: import java.io.*;
import java.util.*;
import java.lang.Math.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String[] st = bf.readLine().split(" ");
if(Integer.parseInt(st[1])==0)
System.out.print(-1);
else {
int f = (Integer.parseInt(st[0])/Integer.parseInt(st[1]));
System.out.print(f);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division.
As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget.
You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q.
Constraints:-
0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined.
Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:-
9 3
Sample Output:-
3
Sample Input:-
8 5
Sample Output:-
1
Explanation:-
8/5 = 1.6 = 1(floor), I have written this Solution Code: D,Q = input().split()
D = int(D)
Q = int(Q)
if(0<=D and Q<=100 and Q >0):
print(int(D/Q))
else:
print('-1'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division.
As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget.
You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q.
Constraints:-
0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined.
Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:-
9 3
Sample Output:-
3
Sample Input:-
8 5
Sample Output:-
1
Explanation:-
8/5 = 1.6 = 1(floor), I have written this Solution Code: #include <iostream>
using namespace std;
int main(){
int n,m;
cin>>n>>m;
if(m==0){cout<<-1;return 0;}
cout<<n/m;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement pow(X, N), which calculates x raised to the power N i.e. (X^N).
Try using a recursive approachThe first line contains T, denoting the number of test cases. Each test case contains a single line containing X, and N.
<b>Constraints:</b>
1 ≤ T ≤ 100
-10.00 ≤ X ≤10.00
-10 ≤ N ≤ 10
For each test case, you need to print the value of X^N. Print up to two places of decimal.
<b>Note:</b>
Please take care that the output can be very large but it will not exceed double the data type value.Input:
1
2.00 -2
Output:
0.25
<b>Explanation:</b>
2^(-2) = 1/2^2 = 1/4 = 0.25, I have written this Solution Code:
// X and Y are numbers
// ignore number of testcases variable
function pow(X, Y) {
// write code here
// console.log the output in a single line,like example
console.log(Math.pow(X, Y).toFixed(2))
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement pow(X, N), which calculates x raised to the power N i.e. (X^N).
Try using a recursive approachThe first line contains T, denoting the number of test cases. Each test case contains a single line containing X, and N.
<b>Constraints:</b>
1 ≤ T ≤ 100
-10.00 ≤ X ≤10.00
-10 ≤ N ≤ 10
For each test case, you need to print the value of X^N. Print up to two places of decimal.
<b>Note:</b>
Please take care that the output can be very large but it will not exceed double the data type value.Input:
1
2.00 -2
Output:
0.25
<b>Explanation:</b>
2^(-2) = 1/2^2 = 1/4 = 0.25, I have written this Solution Code: def power(N,K):
return ("{0:.2f}".format(N**K))
T=int(input())
for i in range(T):
X,N = map(float,input().strip().split())
print(power(X,N)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement pow(X, N), which calculates x raised to the power N i.e. (X^N).
Try using a recursive approachThe first line contains T, denoting the number of test cases. Each test case contains a single line containing X, and N.
<b>Constraints:</b>
1 ≤ T ≤ 100
-10.00 ≤ X ≤10.00
-10 ≤ N ≤ 10
For each test case, you need to print the value of X^N. Print up to two places of decimal.
<b>Note:</b>
Please take care that the output can be very large but it will not exceed double the data type value.Input:
1
2.00 -2
Output:
0.25
<b>Explanation:</b>
2^(-2) = 1/2^2 = 1/4 = 0.25, I have written this Solution Code: import java.util.*;
import java.io.*;
import java.lang.*;
class Main
{
public static void main (String[] args)throws Exception {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(read.readLine());
while(t-- > 0)
{
String str[] = read.readLine().trim().split(" ");
double X = Double.parseDouble(str[0]);
int N = Integer.parseInt(str[1]);
System.out.println(String.format("%.2f", myPow(X, N)));
}
}
public static double myPow(double x, int n) {
if (n == Integer.MIN_VALUE)
n = - (Integer.MAX_VALUE - 1);
if (n == 0)
return 1.0;
else if (n < 0)
return 1 / myPow(x, -n);
else if (n % 2 == 1)
return x * myPow(x, n - 1);
else {
double sqrt = myPow(x, n / 2);
return sqrt * sqrt;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement pow(X, N), which calculates x raised to the power N i.e. (X^N).
Try using a recursive approachThe first line contains T, denoting the number of test cases. Each test case contains a single line containing X, and N.
<b>Constraints:</b>
1 ≤ T ≤ 100
-10.00 ≤ X ≤10.00
-10 ≤ N ≤ 10
For each test case, you need to print the value of X^N. Print up to two places of decimal.
<b>Note:</b>
Please take care that the output can be very large but it will not exceed double the data type value.Input:
1
2.00 -2
Output:
0.25
<b>Explanation:</b>
2^(-2) = 1/2^2 = 1/4 = 0.25, I have written this Solution Code: #include "bits/stdc++.h"
using namespace std;
#define ld long double
#define int long long int
#define speed ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define endl '\n'
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
ld power(ld x, ld n){
if(n == 0)
return 1;
else
return x*power(x, n-1);
}
signed main() {
speed;
int t; cin >> t;
while(t--){
double x; int n;
cin >> x >> n;
if(n < 0)
x = 1.0/x, n *= -1;
cout << setprecision(2) << fixed << power(x, n) << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The universe contains a magic number <b>z</b>. Thor's power is known to <b>x</b> and Loki's power to be <b>y</b>.
One's strength is defined to be <b>z - a</b>, if his power is <b>a</b>. Your task is to find out who among Thor and Loki has the highest strength, and print that strength.
<b>Note:</b> The input and answer may not fit in a 32-bit integer type. In particular, if you are using C++ consider using <em>long long int</em> over <em>int</em>.The first line contains one integer t β the number of test cases.
Each test case consists of one line containing three space-separated integers x, y and z.
<b> Constraints: </b>
1 β€ t β€ 10<sup>4</sup>
1 β€ x, y β€ 10<sup>15</sup>
max(x, y) < z β€ 10<sup>15</sup>For each test case, print a single value - the largest strength among Thor and Loki.Sample Input
2
2 3 4
1 1 5
Sample Output
2
4, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
long z=0,x=0,y=0;
int choice;
Scanner in = new Scanner(System.in);
choice = in.nextInt();
String s="";
int f = 1;
while(f<=choice){
x = in.nextLong();
y = in.nextLong();
z = in.nextLong();
System.out.println((long)(Math.max((z-x),(z-y))));
f++;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The universe contains a magic number <b>z</b>. Thor's power is known to <b>x</b> and Loki's power to be <b>y</b>.
One's strength is defined to be <b>z - a</b>, if his power is <b>a</b>. Your task is to find out who among Thor and Loki has the highest strength, and print that strength.
<b>Note:</b> The input and answer may not fit in a 32-bit integer type. In particular, if you are using C++ consider using <em>long long int</em> over <em>int</em>.The first line contains one integer t β the number of test cases.
Each test case consists of one line containing three space-separated integers x, y and z.
<b> Constraints: </b>
1 β€ t β€ 10<sup>4</sup>
1 β€ x, y β€ 10<sup>15</sup>
max(x, y) < z β€ 10<sup>15</sup>For each test case, print a single value - the largest strength among Thor and Loki.Sample Input
2
2 3 4
1 1 5
Sample Output
2
4, I have written this Solution Code: n = int(input())
for i in range(n):
l = list(map(int,input().split()))
print(l[2]-min(l)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The universe contains a magic number <b>z</b>. Thor's power is known to <b>x</b> and Loki's power to be <b>y</b>.
One's strength is defined to be <b>z - a</b>, if his power is <b>a</b>. Your task is to find out who among Thor and Loki has the highest strength, and print that strength.
<b>Note:</b> The input and answer may not fit in a 32-bit integer type. In particular, if you are using C++ consider using <em>long long int</em> over <em>int</em>.The first line contains one integer t β the number of test cases.
Each test case consists of one line containing three space-separated integers x, y and z.
<b> Constraints: </b>
1 β€ t β€ 10<sup>4</sup>
1 β€ x, y β€ 10<sup>15</sup>
max(x, y) < z β€ 10<sup>15</sup>For each test case, print a single value - the largest strength among Thor and Loki.Sample Input
2
2 3 4
1 1 5
Sample Output
2
4, 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 mod2 = 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;
}
signed main()
{
read(t);
assert(1 <= t && t <= ll(1e4));
while (t--)
{
readc(x, y, z);
assert(1 <= x && x <= ll(1e15));
assert(1 <= y && y <= ll(1e15));
assert(max(x, y) < z && z <= ll(1e15));
int r = 2*z - x - y - 1;
int l = z - max(x, y);
print(r - l + 1);
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The universe contains a magic number <b>z</b>. Thor's power is known to <b>x</b> and Loki's power to be <b>y</b>.
One's strength is defined to be <b>z - a</b>, if his power is <b>a</b>. Your task is to find out who among Thor and Loki has the highest strength, and print that strength.
<b>Note:</b> The input and answer may not fit in a 32-bit integer type. In particular, if you are using C++ consider using <em>long long int</em> over <em>int</em>.The first line contains one integer t β the number of test cases.
Each test case consists of one line containing three space-separated integers x, y and z.
<b> Constraints: </b>
1 β€ t β€ 10<sup>4</sup>
1 β€ x, y β€ 10<sup>15</sup>
max(x, y) < z β€ 10<sup>15</sup>For each test case, print a single value - the largest strength among Thor and Loki.Sample Input
2
2 3 4
1 1 5
Sample Output
2
4, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
int t;
cin>>t;
while(t--)
{
int x, y, z;
cin>>x>>y>>z;
cout<<max(z - y, z- x)<<endl;
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cerr.tie(NULL);
#ifndef ONLINE_JUDGE
if (fopen("INPUT.txt", "r"))
{
freopen("INPUT.txt", "r", stdin);
freopen("OUTPUT.txt", "w", stdout);
}
#endif
solve();
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are N buildings in a row with different heights H[i] (1 <= i <= N).
You are standing on the left side of the first building .From this position you can see the roof of a building <b>i</b> if no building to the left of the i<sup>th</sup> building has a height greater than or equal to the height of the i<sup>th</sup> building.
You are asked to find the number of buildings whose roofs you can see.The first line contains N denoting number of buildings.
The next line contains N space seperated integers denoting heights of the buildings from left to right.
Constraints
1 <= N <= 100000
1 <= H[i] <= 1000000000000000The output should contain one integer which is the number of buildings whose roofs you can see.Sample input:
5
1 2 2 4 3
Sample output:
3
Explanation:-
the building at index 3 will hide before building at index 2 and building at index 5 will hide before building at index 4
Sample input:
5
1 2 3 4 5
Sample output:
5
, I have written this Solution Code: n=int(input())
a=map(int,input().split())
b=[]
mx=-200000
cnt=0
for i in a:
if i>mx:
cnt+=1
mx=i
print(cnt), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are N buildings in a row with different heights H[i] (1 <= i <= N).
You are standing on the left side of the first building .From this position you can see the roof of a building <b>i</b> if no building to the left of the i<sup>th</sup> building has a height greater than or equal to the height of the i<sup>th</sup> building.
You are asked to find the number of buildings whose roofs you can see.The first line contains N denoting number of buildings.
The next line contains N space seperated integers denoting heights of the buildings from left to right.
Constraints
1 <= N <= 100000
1 <= H[i] <= 1000000000000000The output should contain one integer which is the number of buildings whose roofs you can see.Sample input:
5
1 2 2 4 3
Sample output:
3
Explanation:-
the building at index 3 will hide before building at index 2 and building at index 5 will hide before building at index 4
Sample input:
5
1 2 3 4 5
Sample output:
5
, I have written this Solution Code: function numberOfRoofs(arr)
{
let count=1;
let max = arr[0];
for(let i=1;i<arrSize;i++)
{
if(arr[i] > max)
{
count++;
max = arr[i];
}
}
return count;
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are N buildings in a row with different heights H[i] (1 <= i <= N).
You are standing on the left side of the first building .From this position you can see the roof of a building <b>i</b> if no building to the left of the i<sup>th</sup> building has a height greater than or equal to the height of the i<sup>th</sup> building.
You are asked to find the number of buildings whose roofs you can see.The first line contains N denoting number of buildings.
The next line contains N space seperated integers denoting heights of the buildings from left to right.
Constraints
1 <= N <= 100000
1 <= H[i] <= 1000000000000000The output should contain one integer which is the number of buildings whose roofs you can see.Sample input:
5
1 2 2 4 3
Sample output:
3
Explanation:-
the building at index 3 will hide before building at index 2 and building at index 5 will hide before building at index 4
Sample input:
5
1 2 3 4 5
Sample output:
5
, I have written this Solution Code: import java.util.*;
import java.io.*;
class Main{
public static void main(String args[]){
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int []a=new int[n];
for(int i=0;i<n;i++){
a[i]=s.nextInt();
}
int count=1;
int max = a[0];
for(int i=1;i<n;i++)
{
if(a[i] > max)
{
count++;
max = a[i];
}
}
System.out.println(count);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohit has an array of N integers containing all elements from 1 to N, somehow he lost one element from the array.
Given N-1 elements your task is to find the missing one.The first line of input contains a single integer N, the next line contains N-1 space-separated integers.
<b>Constraints:-</b>
1 ≤ N ≤ 1000
1 ≤ elements ≤ NPrint the missing elementSample Input:-
3
3 1
Sample Output:
2
Sample Input:-
5
1 4 5 2
Sample Output:-
3, I have written this Solution Code: def getMissingNo(arr, n):
total = (n+1)*(n)//2
sum_of_A = sum(arr)
return total - sum_of_A
N = int(input())
arr = list(map(int,input().split()))
one = getMissingNo(arr,N)
print(one), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohit has an array of N integers containing all elements from 1 to N, somehow he lost one element from the array.
Given N-1 elements your task is to find the missing one.The first line of input contains a single integer N, the next line contains N-1 space-separated integers.
<b>Constraints:-</b>
1 ≤ N ≤ 1000
1 ≤ elements ≤ NPrint the missing elementSample Input:-
3
3 1
Sample Output:
2
Sample Input:-
5
1 4 5 2
Sample Output:-
3, 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);
int n = sc.nextInt();
int a[] = new int[n-1];
for(int i=0;i<n-1;i++){
a[i]=sc.nextInt();
}
boolean present = false;
for(int i=1;i<=n;i++){
present=false;
for(int j=0;j<n-1;j++){
if(a[j]==i){present=true;}
}
if(present==false){
System.out.print(i);
return;
}
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohit has an array of N integers containing all elements from 1 to N, somehow he lost one element from the array.
Given N-1 elements your task is to find the missing one.The first line of input contains a single integer N, the next line contains N-1 space-separated integers.
<b>Constraints:-</b>
1 ≤ N ≤ 1000
1 ≤ elements ≤ NPrint the missing elementSample Input:-
3
3 1
Sample Output:
2
Sample Input:-
5
1 4 5 2
Sample Output:-
3, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a[n-1];
for(int i=0;i<n-1;i++){
cin>>a[i];
}
sort(a,a+n-1);
for(int i=1;i<n;i++){
if(i!=a[i-1]){cout<<i<<endl;return 0;}
}
cout<<n;
}
, In this Programming Language: C++, 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: The universe contains a magic number <b>z</b>. Thor's power is known to <b>x</b> and Loki's power to be <b>y</b>.
One's strength is defined to be <b>z - a</b>, if his power is <b>a</b>. Your task is to find out who among Thor and Loki has the highest strength, and print that strength.
<b>Note:</b> The input and answer may not fit in a 32-bit integer type. In particular, if you are using C++ consider using <em>long long int</em> over <em>int</em>.The first line contains one integer t β the number of test cases.
Each test case consists of one line containing three space-separated integers x, y and z.
<b> Constraints: </b>
1 β€ t β€ 10<sup>4</sup>
1 β€ x, y β€ 10<sup>15</sup>
max(x, y) < z β€ 10<sup>15</sup>For each test case, print a single value - the largest strength among Thor and Loki.Sample Input
2
2 3 4
1 1 5
Sample Output
2
4, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
long z=0,x=0,y=0;
int choice;
Scanner in = new Scanner(System.in);
choice = in.nextInt();
String s="";
int f = 1;
while(f<=choice){
x = in.nextLong();
y = in.nextLong();
z = in.nextLong();
System.out.println((long)(Math.max((z-x),(z-y))));
f++;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The universe contains a magic number <b>z</b>. Thor's power is known to <b>x</b> and Loki's power to be <b>y</b>.
One's strength is defined to be <b>z - a</b>, if his power is <b>a</b>. Your task is to find out who among Thor and Loki has the highest strength, and print that strength.
<b>Note:</b> The input and answer may not fit in a 32-bit integer type. In particular, if you are using C++ consider using <em>long long int</em> over <em>int</em>.The first line contains one integer t β the number of test cases.
Each test case consists of one line containing three space-separated integers x, y and z.
<b> Constraints: </b>
1 β€ t β€ 10<sup>4</sup>
1 β€ x, y β€ 10<sup>15</sup>
max(x, y) < z β€ 10<sup>15</sup>For each test case, print a single value - the largest strength among Thor and Loki.Sample Input
2
2 3 4
1 1 5
Sample Output
2
4, I have written this Solution Code: n = int(input())
for i in range(n):
l = list(map(int,input().split()))
print(l[2]-min(l)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The universe contains a magic number <b>z</b>. Thor's power is known to <b>x</b> and Loki's power to be <b>y</b>.
One's strength is defined to be <b>z - a</b>, if his power is <b>a</b>. Your task is to find out who among Thor and Loki has the highest strength, and print that strength.
<b>Note:</b> The input and answer may not fit in a 32-bit integer type. In particular, if you are using C++ consider using <em>long long int</em> over <em>int</em>.The first line contains one integer t β the number of test cases.
Each test case consists of one line containing three space-separated integers x, y and z.
<b> Constraints: </b>
1 β€ t β€ 10<sup>4</sup>
1 β€ x, y β€ 10<sup>15</sup>
max(x, y) < z β€ 10<sup>15</sup>For each test case, print a single value - the largest strength among Thor and Loki.Sample Input
2
2 3 4
1 1 5
Sample Output
2
4, 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 mod2 = 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;
}
signed main()
{
read(t);
assert(1 <= t && t <= ll(1e4));
while (t--)
{
readc(x, y, z);
assert(1 <= x && x <= ll(1e15));
assert(1 <= y && y <= ll(1e15));
assert(max(x, y) < z && z <= ll(1e15));
int r = 2*z - x - y - 1;
int l = z - max(x, y);
print(r - l + 1);
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The universe contains a magic number <b>z</b>. Thor's power is known to <b>x</b> and Loki's power to be <b>y</b>.
One's strength is defined to be <b>z - a</b>, if his power is <b>a</b>. Your task is to find out who among Thor and Loki has the highest strength, and print that strength.
<b>Note:</b> The input and answer may not fit in a 32-bit integer type. In particular, if you are using C++ consider using <em>long long int</em> over <em>int</em>.The first line contains one integer t β the number of test cases.
Each test case consists of one line containing three space-separated integers x, y and z.
<b> Constraints: </b>
1 β€ t β€ 10<sup>4</sup>
1 β€ x, y β€ 10<sup>15</sup>
max(x, y) < z β€ 10<sup>15</sup>For each test case, print a single value - the largest strength among Thor and Loki.Sample Input
2
2 3 4
1 1 5
Sample Output
2
4, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
int t;
cin>>t;
while(t--)
{
int x, y, z;
cin>>x>>y>>z;
cout<<max(z - y, z- x)<<endl;
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cerr.tie(NULL);
#ifndef ONLINE_JUDGE
if (fopen("INPUT.txt", "r"))
{
freopen("INPUT.txt", "r", stdin);
freopen("OUTPUT.txt", "w", stdout);
}
#endif
solve();
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: def compound_interest(principle, rate, time):
Amount = principle * (pow((1 + rate / 100), time))
CI = Amount - principle
print( '%.2f'%CI)
principle,rate,time=map(int, input().split())
compound_interest(principle,rate,time), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: function calculateCI(P, R, T)
{
let interest = P * (Math.pow(1.0 + R/100.0, T) - 1);
return interest.toFixed(2);
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int p,r,t;
cin>>p>>r>>t;
double rate= (float)r/100;
double amt = (float)p*(pow(1+rate,t));
cout << fixed << setprecision(2) << (amt - p);
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.lang.Math;
class Main {
public static void main (String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] s= br.readLine().split(" ");
double[] darr = new double[s.length];
for(int i=0;i<s.length;i++){
darr[i] = Double.parseDouble(s[i]);
}
double ans = darr[0]*Math.pow(1+darr[1]/100,darr[2])-darr[0];
System.out.printf("%.2f",ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integer N and K, find the minimum number of times N must be multiplied by X to make it divisible by (2<sup>K</sup>).
Where X = Summation (2<sup>(4*i)</sup>) for 1 <= i <= 25.The first and the only line of input contains two space separated integers N and K.
Constraints
1 <= N <= 10^18
1 <= K <= 10^18Print a single integer which is the minimum number of times N must be multiplied by X to make it divisible by (2<sup>K</sup>).Sample Input 1
40 4
Sample Output 1
1
Sample Input
40 3
Sample Output
0, I have written this Solution Code: import java.util.InputMismatchException;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
public class Main {
InputStream is;
PrintWriter out;
String INPUT = "";
int MAX = (int) 1e5, MOD = (int)1e9+7;
void solve(int TC) {
long n = nl();
long k = nl();
int p = 0;
while(n>0 && n%2==0) {
n/=2;
++p;
}
if(p>=k) {pn(0);return;}
k -= p;
long ans = (k+3L)/4L;
pn(ans);
}
boolean TestCases = false;
public static void main(String[] args) throws Exception { new Main().run(); }
long pow(long a, long b) {
if(b==0 || a==1) return 1;
long o = 1;
for(long p = b; p > 0; p>>=1) {
if((p&1)==1) o = (o*a) % MOD;
a = (a*a) % MOD;
} return o;
}
long inv(long x) {
long o = 1;
for(long p = MOD-2; p > 0; p>>=1) {
if((p&1)==1)o = (o*x)%MOD;
x = (x*x)%MOD;
} return o;
}
long gcd(long a, long b) { return (b==0) ? a : gcd(b,a%b); }
int gcd(int a, int b) { return (b==0) ? a : gcd(b,a%b); }
void run() throws Exception {
is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
int T = TestCases ? ni() : 1;
for(int t=1;t<=T;t++) solve(t);
out.flush();
if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
}
void p(Object o) { out.print(o); }
void pn(Object o) { out.println(o); }
void pni(Object o) { out.println(o);out.flush(); }
double PI = 3.141592653589793238462643383279502884197169399;
int ni() {
int num = 0, b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-') {
minus = true;
b = readByte();
}
while(true) {
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
long nl() {
long num = 0;
int b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-') {
minus = true;
b = readByte();
}
while(true) {
if(b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
double nd() { return Double.parseDouble(ns()); }
char nc() { return (char)skip(); }
int BUF_SIZE = 1024 * 8;
byte[] inbuf = new byte[BUF_SIZE];
int lenbuf = 0, ptrbuf = 0;
int readByte() {
if(lenbuf == -1)throw new InputMismatchException();
if(ptrbuf >= lenbuf){
ptrbuf = 0;
try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
if(lenbuf <= 0)return -1;
} return inbuf[ptrbuf++];
}
boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
String ns() {
int b = skip();
StringBuilder sb = new StringBuilder();
while(!(isSpaceChar(b))) {
sb.appendCodePoint(b); b = readByte();
} return sb.toString();
}
char[] ns(int n) {
char[] buf = new char[n];
int b = skip(), p = 0;
while(p < n && !(isSpaceChar(b))){
buf[p++] = (char)b;
b = readByte();
} return n == p ? buf : Arrays.copyOf(buf, p);
}
void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integer N and K, find the minimum number of times N must be multiplied by X to make it divisible by (2<sup>K</sup>).
Where X = Summation (2<sup>(4*i)</sup>) for 1 <= i <= 25.The first and the only line of input contains two space separated integers N and K.
Constraints
1 <= N <= 10^18
1 <= K <= 10^18Print a single integer which is the minimum number of times N must be multiplied by X to make it divisible by (2<sup>K</sup>).Sample Input 1
40 4
Sample Output 1
1
Sample Input
40 3
Sample Output
0, I have written this Solution Code: [n,k]=[int(j) for j in input().split()]
a=0
while n%2==0:
a+=1
n=n//2
if k>a:
print((k-a-1)//4+1)
else:
print(0), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integer N and K, find the minimum number of times N must be multiplied by X to make it divisible by (2<sup>K</sup>).
Where X = Summation (2<sup>(4*i)</sup>) for 1 <= i <= 25.The first and the only line of input contains two space separated integers N and K.
Constraints
1 <= N <= 10^18
1 <= K <= 10^18Print a single integer which is the minimum number of times N must be multiplied by X to make it divisible by (2<sup>K</sup>).Sample Input 1
40 4
Sample Output 1
1
Sample Input
40 3
Sample Output
0, 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,k;
cin>>n>>k;
while(k&&n%2==0){
n/=2;
--k;
}
cout<<(k+3)/4;
#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 a string s of length n. Find all the repeating characters and count their occurrence. A character is a repeating character if it occurs more than once.First line contains n.
Next line contains the string s.
<b>Constraints</b>
1 ≤ n ≤ 10<sup>5</sup>
s contains only lowercase English letters.Print all the repeating characters and their frequency. Print in order from 'a' to 'z'.Input:
6
banana
Output:
a 3
n 2
Explanation :
b occurs only once., 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());
String s=in.next();
int a[] = new int[26];
Arrays.fill(a,0);
for(int i=0;i<n;i++)
{
int j=s.charAt(i) - 'a';
a[j]++;
}
for(int i=0;i<26;i++){
if(a[i] > 1){
out.println((char)('a' + i) + " " + a[i]);
}
}
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: You are given an array of length N and an integer K. The array will contain integers numbered through 1 to K. Your task is to calculate the maximum length of the subarray containing not more than K-1 distinct numbers(atleast one number which does not occur in the subarray)The first line contains two integers N and K
The second line contains N space-separated integers
Constraints
1<=K , N<=100000
1<=A[I]<=100000Print a single line containing one integer β the maximum length of a valid subsegment.Sample Input
6 2
1 1 1 2 2 1
Sample output:-
3
Sample Input:-
5 3
1 1 2 2 1
Sample Output:-
5, 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 str[]=br.readLine().split(" ");
int n=Integer.parseInt(str[0]);
int k=Integer.parseInt(str[1]);
int a[]=new int[n];
int m=k-1;
str=br.readLine().split(" ");
for(int i=0;i<n;i++){
a[i]=Integer.parseInt(str[i]);
}
int b[]=new int[100001];
long cnt=0;
int low=0,p=0,q=0;
for(int i=0;i<n;i++){
b[a[i]]++;
if(b[a[i]]==1)
cnt++;
while(cnt>m){
b[a[low]]--;
if(b[a[low]]==0)
cnt--;
low++;
}
if((i-low+1)>=(q-p+1)){
q=i;
p=low;
}
}
System.out.println(q-p+1);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array of length N and an integer K. The array will contain integers numbered through 1 to K. Your task is to calculate the maximum length of the subarray containing not more than K-1 distinct numbers(atleast one number which does not occur in the subarray)The first line contains two integers N and K
The second line contains N space-separated integers
Constraints
1<=K , N<=100000
1<=A[I]<=100000Print a single line containing one integer β the maximum length of a valid subsegment.Sample Input
6 2
1 1 1 2 2 1
Sample output:-
3
Sample Input:-
5 3
1 1 2 2 1
Sample Output:-
5, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int t;
t=1;
while(t--){
long n,k;
cin>>n>>k;
long a[n];
long sum=0,b[n];
for(long i=0;i<n;i++){cin>>a[i];sum+=a[i];b[i]=sum;}
int cnt[k+1];
for(int i=0;i<=k;i++){cnt[i]=0;}
long x=0;
int ans=0;
map<int,int> mp;
int diff = 0;
for(int i=0, l=0, r=0; i<n; i++)
{
if(mp[a[i]] == 0) diff++;
mp[a[i]]++;
if(diff == k)
{
while(diff == k)
{
mp[a[l]]--;
if(mp[a[l]] == 0) diff--;
l++;
}
}
ans = max(ans, i -l + 1);
}
cout<<ans<<endl;
}}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:-
T(Β°c) = (T(Β°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b>
Constraints:-
-10^3 <= F <= 10^3
<b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1:
77
Sample Output 1:
25
Sample Input 2:-
-40
Sample Output 2:-
-40
<b>Explanation 1</b>:
T(Β°c) = (T(Β°f) - 32)*5/9
T(Β°c) = (77-32)*5/9
T(Β°c) =25, I have written this Solution Code: void farhenheitToCelsius(int n){
n-=32;
n/=9;
n*=5;
cout<<n;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:-
T(Β°c) = (T(Β°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b>
Constraints:-
-10^3 <= F <= 10^3
<b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1:
77
Sample Output 1:
25
Sample Input 2:-
-40
Sample Output 2:-
-40
<b>Explanation 1</b>:
T(Β°c) = (T(Β°f) - 32)*5/9
T(Β°c) = (77-32)*5/9
T(Β°c) =25, I have written this Solution Code: Fahrenheit= int(input())
Celsius = int(((Fahrenheit-32)*5)/9 )
print(Celsius), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:-
T(Β°c) = (T(Β°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b>
Constraints:-
-10^3 <= F <= 10^3
<b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1:
77
Sample Output 1:
25
Sample Input 2:-
-40
Sample Output 2:-
-40
<b>Explanation 1</b>:
T(Β°c) = (T(Β°f) - 32)*5/9
T(Β°c) = (77-32)*5/9
T(Β°c) =25, I have written this Solution Code: static void farhrenheitToCelsius(int farhrenheit)
{
int celsius = ((farhrenheit-32)*5)/9;
System.out.println(celsius);
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, the task is to find the number of divisors of N which are divisible by 2.The input line contains T, denoting the number of testcases. First line of each testcase contains integer N
Constraints:
1 <= T <= 50
1 <= N <= 10^9For each testcase in new line, you need to print the number of divisors of N which are exactly divisble by 2Input:
2
9
8
Output
0
3, I have written this Solution Code: import math
n = int(input())
for i in range(n):
x = int(input())
count = 0
for i in range(1, int(math.sqrt(x))+1):
if x % i == 0:
if (i%2 == 0):
count+=1
if ((x/i) %2 == 0):
count+=1
print(count), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, the task is to find the number of divisors of N which are divisible by 2.The input line contains T, denoting the number of testcases. First line of each testcase contains integer N
Constraints:
1 <= T <= 50
1 <= N <= 10^9For each testcase in new line, you need to print the number of divisors of N which are exactly divisble by 2Input:
2
9
8
Output
0
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));
int t = Integer.parseInt(br.readLine());
while(t-->0){
int n = Integer.parseInt(br.readLine());
int count=0;
for(int i=1;i<=Math.sqrt(n);i++){
if(n%i == 0)
{
if(i%2==0) {
count++;
}
if(i*i != n && (n/i)%2==0) {
count++;
}
}
}
System.out.println(count);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, the task is to find the number of divisors of N which are divisible by 2.The input line contains T, denoting the number of testcases. First line of each testcase contains integer N
Constraints:
1 <= T <= 50
1 <= N <= 10^9For each testcase in new line, you need to print the number of divisors of N which are exactly divisble by 2Input:
2
9
8
Output
0
3, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
long long n;
cin>>n;
if(n&1){cout<<0<<endl;continue;}
long x=sqrt(n);
int cnt=0;
for(long long i=1;i<=x;i++){
if(!(n%i)){
if(!(i%2)){cnt++;}
if(i*i!=n){
if(!((n/i)%2)){cnt++;}
}
}
}
cout<<cnt<<endl;}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N. Determine if it has exactly 3 positive divisors all of which are pairwise distinct.<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>solve()</b> that takes an integer N as a parameter.
<b>Constraints</b>
1<=N<=10<sup>12</sup>Return "Yes" if the number has exactly three distinct positive divisors and "No" otherwise.Sample Input:
4
Sample Output:
Yes
4 has only three divisors 1, 2 and 4., I have written this Solution Code: class Solution {
public static String solve(long n) {
final int s = 1000001;
BitSet p = new BitSet(s);
p.set(0);
p.set(1);
for (int i = 2; i * i < s; i++) {
for (int j = i * i; j < s && !p.get(i); j += i) {
p.set(j);
}
}
long r = (long) Math.sqrt(n);
return (r * r == n && !p.get((int) r)) ? "Yes" : "No";
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, the task is to find the number of divisors of N which are divisible by 2.The input line contains T, denoting the number of testcases. First line of each testcase contains integer N
Constraints:
1 <= T <= 50
1 <= N <= 10^9For each testcase in new line, you need to print the number of divisors of N which are exactly divisble by 2Input:
2
9
8
Output
0
3, I have written this Solution Code: import math
n = int(input())
for i in range(n):
x = int(input())
count = 0
for i in range(1, int(math.sqrt(x))+1):
if x % i == 0:
if (i%2 == 0):
count+=1
if ((x/i) %2 == 0):
count+=1
print(count), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, the task is to find the number of divisors of N which are divisible by 2.The input line contains T, denoting the number of testcases. First line of each testcase contains integer N
Constraints:
1 <= T <= 50
1 <= N <= 10^9For each testcase in new line, you need to print the number of divisors of N which are exactly divisble by 2Input:
2
9
8
Output
0
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));
int t = Integer.parseInt(br.readLine());
while(t-->0){
int n = Integer.parseInt(br.readLine());
int count=0;
for(int i=1;i<=Math.sqrt(n);i++){
if(n%i == 0)
{
if(i%2==0) {
count++;
}
if(i*i != n && (n/i)%2==0) {
count++;
}
}
}
System.out.println(count);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, the task is to find the number of divisors of N which are divisible by 2.The input line contains T, denoting the number of testcases. First line of each testcase contains integer N
Constraints:
1 <= T <= 50
1 <= N <= 10^9For each testcase in new line, you need to print the number of divisors of N which are exactly divisble by 2Input:
2
9
8
Output
0
3, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
long long n;
cin>>n;
if(n&1){cout<<0<<endl;continue;}
long x=sqrt(n);
int cnt=0;
for(long long i=1;i<=x;i++){
if(!(n%i)){
if(!(i%2)){cnt++;}
if(i*i!=n){
if(!((n/i)%2)){cnt++;}
}
}
}
cout<<cnt<<endl;}
}
, In this Programming Language: C++, 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: Maruti is a Bill manager in the Electricity department in his municipality. Being a newbie, he is not that good at calculation. So as a good friend of Maruti, calculate the bill amount for given electricity unit counts.
<b>Note:</b>Per unit electricity rate is given below.
For the first 50 units, Rs. 0.50/unit
For the next 100 units, Rs. 0.75/unit
For the next 100 units, Rs. 1.25/unit
For units above 250, Rs. 1.50/unit
An additional surcharge of 20% is added to the bill.
You are given an integer n (count of electricity units), then return the total amount Maruti has to pay.
Print answers up to 2 decimal places.An integer n (count of electricity units) is given as input.
<b>Constraints</b>
1 <b>≤</b> n <b>≤</b> 10<sup>5</sup>A single number that represents the total amount that Maruti has to pay.Sample Input:
100
Sample Output:
75.00
Explanation:
Bill Amount=0.5*50+0.75*50=25+37.5=62.5
Bill after 20% additional Charge=62.5+12.50=75.00, I have written this Solution Code: import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
double ans=0;
ans+=0.5*Math.min(n,50);
if(n>50){
ans+=0.75*Math.min(n-50,100);
}
if(n>150){
ans+=1.25*Math.min(n-150,100);
}
if(n>250)
ans+=1.50*(n-250);
//Additional Charge
ans+=0.20*ans;
System.out.printf("%.2f",ans);
return;
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two numbers n and p. You need to find n raised to the power p.<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>RecursivePower</b> that takes the integer n and p as a parameter.
Constraints:
1 <= T <= 10
1 <= n, p <= 9Return n^p.Sample Input:
3
2 3
9 9
2 9
Sample Output:
8
387420489β¬
512
Explanation:
Test case 2: 387420489 is the value obtained when 9 is raised to the power of 9.
Test case 3: 512 is the value obtained when 2 is raised to the power of 9, I have written this Solution Code:
static int Power(int n,int p)
{
if(p==0)
return 1;
return n*Power(n,p-1);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a big number in form of a string A of characters from 0 to 9.
Check whether the given number is divisible by 30 .The first argument is the string A.
<b>Constraints</b>
1 ≤ |A| ≤ 10<sup>5</sup>Return "Yes" if it is divisible by 30 and "No" otherwise. Sample Input :
3033330
Sample Output:
Yes, 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 a= br.readLine();
int sum=0;
int n=a.length();
int s=0;
for(int i=0; i<n; i++){
sum=sum+ (a.charAt(i) - '0');
if(i == n-1){
s= (a.charAt(i) - '0');
}
}
if(sum%3==0 && s==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: You are given a big number in form of a string A of characters from 0 to 9.
Check whether the given number is divisible by 30 .The first argument is the string A.
<b>Constraints</b>
1 ≤ |A| ≤ 10<sup>5</sup>Return "Yes" if it is divisible by 30 and "No" otherwise. Sample Input :
3033330
Sample Output:
Yes, I have written this Solution Code: /**
* Author : tourist1256
* Time : 2022-02-10 11:06:49
**/
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 2351
#endif
int solve(string a) {
int n = a.size();
int sum = 0;
if (a[n - 1] != '0') {
return 0;
}
for (auto &it : a) {
sum += (it - '0');
}
debug(sum % 3);
if (sum % 3 == 0) {
return 1;
}
return 0;
}
int32_t main() {
ios_base::sync_with_stdio(NULL);
cin.tie(0);
string str;
cin >> str;
int res = solve(str);
if (res) {
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: You are given a big number in form of a string A of characters from 0 to 9.
Check whether the given number is divisible by 30 .The first argument is the string A.
<b>Constraints</b>
1 ≤ |A| ≤ 10<sup>5</sup>Return "Yes" if it is divisible by 30 and "No" otherwise. Sample Input :
3033330
Sample Output:
Yes, I have written this Solution Code: A=int(input())
if A%30==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: You are given a matrix Mat of m rows and n columns. The matrix is boolean so the elements of the matrix can only be either 0 or 1.
Now, if any row of the matrix contains a 1, then you need to fill that whole row with 1. After doing the mentioned operation, you need to print the modified matrix.The first line of input contains T denoting the number of test cases. T test cases follow.
The first line of each test case contains m and n denotes the number of rows and a number of columns.
Then next m lines contain n elements denoting the elements of the matrix.
Constraints:
1 ≤ T ≤ 20
1 ≤ m, n ≤ 700
Mat[I][j] β {0,1}For each testcase, in a new line, print the modified matrix.Input:
1
5 4
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Output:
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1
Explanation:
Rows = 5 and columns = 4
The given matrix is
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Evidently, the first row contains a 1 so fill the whole row with 1. The third row also contains a 1 so that row will be filled too. Finally, the last row contains a 1 and therefore it needs to be filled with 1 too.
The final matrix is
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1, I have written this Solution Code: t=int(input())
while t!=0:
m,n=input().split()
m,n=int(m),int(n)
for i in range(m):
arr=input().strip()
if '1' in arr:
arr='1 '*n
else:
arr='0 '*n
print(arr)
t-=1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a matrix Mat of m rows and n columns. The matrix is boolean so the elements of the matrix can only be either 0 or 1.
Now, if any row of the matrix contains a 1, then you need to fill that whole row with 1. After doing the mentioned operation, you need to print the modified matrix.The first line of input contains T denoting the number of test cases. T test cases follow.
The first line of each test case contains m and n denotes the number of rows and a number of columns.
Then next m lines contain n elements denoting the elements of the matrix.
Constraints:
1 ≤ T ≤ 20
1 ≤ m, n ≤ 700
Mat[I][j] β {0,1}For each testcase, in a new line, print the modified matrix.Input:
1
5 4
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Output:
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1
Explanation:
Rows = 5 and columns = 4
The given matrix is
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Evidently, the first row contains a 1 so fill the whole row with 1. The third row also contains a 1 so that row will be filled too. Finally, the last row contains a 1 and therefore it needs to be filled with 1 too.
The final matrix is
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define N 1000
int a[N][N];
// Driver code
int main()
{
int t;
cin>>t;
while(t--){
int n,m;
cin>>n>>m;
bool b[n];
for(int i=0;i<n;i++){
b[i]=false;
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>a[i][j];
if(a[i][j]==1){
b[i]=true;
}
}
}
for(int i=0;i<n;i++){
if(b[i]){
for(int j=0;j<m;j++){
cout<<1<<" ";
}}
else{
for(int j=0;j<m;j++){
cout<<0<<" ";
}
}
cout<<endl;
}
}}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a matrix Mat of m rows and n columns. The matrix is boolean so the elements of the matrix can only be either 0 or 1.
Now, if any row of the matrix contains a 1, then you need to fill that whole row with 1. After doing the mentioned operation, you need to print the modified matrix.The first line of input contains T denoting the number of test cases. T test cases follow.
The first line of each test case contains m and n denotes the number of rows and a number of columns.
Then next m lines contain n elements denoting the elements of the matrix.
Constraints:
1 ≤ T ≤ 20
1 ≤ m, n ≤ 700
Mat[I][j] β {0,1}For each testcase, in a new line, print the modified matrix.Input:
1
5 4
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Output:
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1
Explanation:
Rows = 5 and columns = 4
The given matrix is
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Evidently, the first row contains a 1 so fill the whole row with 1. The third row also contains a 1 so that row will be filled too. Finally, the last row contains a 1 and therefore it needs to be filled with 1 too.
The final matrix is
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) throws Exception{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader bf = new BufferedReader(isr);
int t = Integer.parseInt(bf.readLine());
while (t-- > 0){
String inputs[] = bf.readLine().split(" ");
int m = Integer.parseInt(inputs[0]);
int n = Integer.parseInt(inputs[1]);
String[] matrix = new String[m];
for(int i=0; i<m; i++){
matrix[i] = bf.readLine();
}
StringBuffer ones = new StringBuffer("");
StringBuffer zeros = new StringBuffer("");
for(int i=0; i<n; i++){
ones.append("1 ");
zeros.append("0 ");
}
for(int i=0; i<m; i++){
if(matrix[i].contains("1")){
System.out.println(ones);
}else{
System.out.println(zeros);
}
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of length N in which you can swap two elements if their sum is odd i.e for every i (1 to N) and j (1 to N) if (Arr[i] + Arr[j]) is odd then you can swap these elements.
What is the lexicographically smallest array you can obtain?First line of input contains a single integer N. Next line contains N space separated integers depicting the elements of the array.
Constraints:-
1 <= N <= 100000
1 <= Arr[i] <= 100000Print N space separated elements i. e the array which is the lexicographically smallest possibleSample Input:-
3
4 1 7
Sample Output:-
1 4 7
Explanation:-
Swap numbers at indices 1 and 2 as their sum 4 + 1 = 5 is odd
Sample Input:-
2
2 4
Sample Output:-
2 4
Sample Input:-
2
5 3
Sample Output:-
5 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));
int n = Integer.parseInt(br.readLine().trim());
String array[] = br.readLine().trim().split(" ");
StringBuilder sb = new StringBuilder("");
int[] arr = new int[n];
int oddCount = 0,
evenCount = 0;
for(int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(array[i]);
if(arr[i] % 2 == 0)
++evenCount;
else
++oddCount;
}
if(evenCount > 0 && oddCount > 0)
Arrays.sort(arr);
for(int i = 0; i < n; i++)
sb.append(arr[i] + " ");
System.out.println(sb.substring(0, sb.length() - 1));
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of length N in which you can swap two elements if their sum is odd i.e for every i (1 to N) and j (1 to N) if (Arr[i] + Arr[j]) is odd then you can swap these elements.
What is the lexicographically smallest array you can obtain?First line of input contains a single integer N. Next line contains N space separated integers depicting the elements of the array.
Constraints:-
1 <= N <= 100000
1 <= Arr[i] <= 100000Print N space separated elements i. e the array which is the lexicographically smallest possibleSample Input:-
3
4 1 7
Sample Output:-
1 4 7
Explanation:-
Swap numbers at indices 1 and 2 as their sum 4 + 1 = 5 is odd
Sample Input:-
2
2 4
Sample Output:-
2 4
Sample Input:-
2
5 3
Sample Output:-
5 3, I have written this Solution Code: n=int(input())
p=[int(x) for x in input().split()[:n]]
o=0;e=0
for i in range(n):
if (p[i] % 2 == 1):
o += 1;
else:
e += 1;
if (o > 0 and e > 0):
p.sort();
for i in range(n):
print(p[i], end = " ");, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of length N in which you can swap two elements if their sum is odd i.e for every i (1 to N) and j (1 to N) if (Arr[i] + Arr[j]) is odd then you can swap these elements.
What is the lexicographically smallest array you can obtain?First line of input contains a single integer N. Next line contains N space separated integers depicting the elements of the array.
Constraints:-
1 <= N <= 100000
1 <= Arr[i] <= 100000Print N space separated elements i. e the array which is the lexicographically smallest possibleSample Input:-
3
4 1 7
Sample Output:-
1 4 7
Explanation:-
Swap numbers at indices 1 and 2 as their sum 4 + 1 = 5 is odd
Sample Input:-
2
2 4
Sample Output:-
2 4
Sample Input:-
2
5 3
Sample Output:-
5 3, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
long long a[n];
bool win=false,win1=false;
for(int i=0;i<n;i++){
cin>>a[i];
if(a[i]&1){win=true;}
if(a[i]%2==0){win1=true;}
}
if(win==true && win1==true){sort(a,a+n);}
for(int i=0;i<n;i++){
cout<<a[i]<<" ";
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: While doing homework, Nobita stuck on a problem and asks for your help.
Problem statement:-
Given three integers X, Y, and N. Your task is to check if it is possible to form N by using only combinations of X and Y.
i.e check if there exist any P and Q such that P*X + Q*Y = N
Note:- P and Q can be negativeThe input contains only three integers X, Y, and N.
Constraints:-
1 <= X, Y, N <= 100000Print "YES" if it is possible to form N else print "NO".Sample Input:-
3 5 18
Sample Output:-
YES
Explanation:-
1 * 3 + 3 * 5 = 18 (P = 1, Q = 3)
Sample Input:-
4 8 15
Sample Output:-
NO, 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 input[] = br.readLine().trim().split(" ");
int x = Integer.parseInt(input[0]),
y = Integer.parseInt(input[1]),
n = Integer.parseInt(input[2]);
boolean flag = false;
for(int q = 1; q <= 100000; q++) {
if((n - (q * y)) % x == 0) {
System.out.println("YES");
flag = true;
break;
}
}
if(!flag)
System.out.println("NO");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: While doing homework, Nobita stuck on a problem and asks for your help.
Problem statement:-
Given three integers X, Y, and N. Your task is to check if it is possible to form N by using only combinations of X and Y.
i.e check if there exist any P and Q such that P*X + Q*Y = N
Note:- P and Q can be negativeThe input contains only three integers X, Y, and N.
Constraints:-
1 <= X, Y, N <= 100000Print "YES" if it is possible to form N else print "NO".Sample Input:-
3 5 18
Sample Output:-
YES
Explanation:-
1 * 3 + 3 * 5 = 18 (P = 1, Q = 3)
Sample Input:-
4 8 15
Sample Output:-
NO, I have written this Solution Code: l,m,z=input().split()
x=int(l)
y=int(m)
n=int(z)
flag=0
for i in range(1,n):
sum1=n-i*y
sum2=n+i*y
if(sum1%x==0 or sum2%y==0):
flag=1
break
if flag==1:
print("YES")
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: While doing homework, Nobita stuck on a problem and asks for your help.
Problem statement:-
Given three integers X, Y, and N. Your task is to check if it is possible to form N by using only combinations of X and Y.
i.e check if there exist any P and Q such that P*X + Q*Y = N
Note:- P and Q can be negativeThe input contains only three integers X, Y, and N.
Constraints:-
1 <= X, Y, N <= 100000Print "YES" if it is possible to form N else print "NO".Sample Input:-
3 5 18
Sample Output:-
YES
Explanation:-
1 * 3 + 3 * 5 = 18 (P = 1, Q = 3)
Sample Input:-
4 8 15
Sample Output:-
NO, 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 1000001
#define MOD 1000000000000007
#define read(type) readInt<type>()
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int cnt[max1];
signed main(){
int t;t=1;
while(t--){
int x,y,n;
cin>>x>>y>>n;
int p=__gcd(x,y);
if(n%p==0){out("YES");}
else{
out("NO");
}
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are n cities in the universe and our beloved Spider-Man is in city 1. He doesn't like to travel by vehicles, so he shot webs forming edges between some pairs of cities. Eventually, there were m edges and each had some cost associated with it.
Spider-Man now defines the cost of a path p from cities p<sub>1</sub> to p<sub>k</sub> as w<sub>1</sub> + 2w<sub>2</sub> + 3w<sub>3</sub> . . . + (k-1)*w<sub>k-1</sub>, where w<sub>i</sub> is the cost of an edge from p<sub>i</sub> to p<sub>i+1</sub>.
Thus, the minimum distance between cities i and j is the smallest cost of a path starting from i and ending at j.
Find the minimum distance from city 1 to all the cities i (1 β€ i β€ n). If there exists no way to go from city 1 to city i, print -1.
<b>Note: </b>
All the edges are bidirectional. There may be multiple edges and self-loops in the input.The first line contains two space separated integers n and m - the number of nodes and edges respectively.
The next m lines contain three-space separated integers x, y, w - representing an edge between x and y with cost w.
<b>Constraints:</b>
1 β€ n β€ 3000
0 β€ m β€ 10000
1 β€ x, y β€ n
1 β€ w β€ 10<sup>9</sup>Output n lines. In the i<sup>th</sup> line, output the minimum distance from city 1 to the i<sup>th</sup> city. If there exists no such path, output -1.Sample Input
6 5
2 4 3
2 3 4
2 1 2
2 5 6
1 5 2
Sample Output
0
2
10
8
2
-1
Explanation:
Shortest path from 1 to 3 is (1->2->3) with total weight= 1*2+2*4=10
Shortest path from 1 to 5 is (1->5) with total weight= 1*2=2
There doesn't exist any path from 1 to 6 so print -1
, I have written this Solution Code:
import sys
from collections import defaultdict
from heapq import heappush, heappop
n, m = map(int, input().split())
d = defaultdict(list)
dist = [sys.maxsize]*n
dist[0] = 0
for _ in range(m):
start, dest, wt = map(int, input().split())
d[start-1].append((dest-1, wt))
d[dest-1].append((start-1, wt))
heap = [(0, 0, 0)]
while heap:
count, cost, u= heappop(heap)
for vertex, weight in d[u]:
if dist[vertex] > cost + weight*(count+1):
dist[vertex] = cost + weight*(count+1)
heappush(heap, (count+1, dist[vertex], vertex))
for d in dist:
if d == sys.maxsize:
print(-1)
else:
print(d), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are n cities in the universe and our beloved Spider-Man is in city 1. He doesn't like to travel by vehicles, so he shot webs forming edges between some pairs of cities. Eventually, there were m edges and each had some cost associated with it.
Spider-Man now defines the cost of a path p from cities p<sub>1</sub> to p<sub>k</sub> as w<sub>1</sub> + 2w<sub>2</sub> + 3w<sub>3</sub> . . . + (k-1)*w<sub>k-1</sub>, where w<sub>i</sub> is the cost of an edge from p<sub>i</sub> to p<sub>i+1</sub>.
Thus, the minimum distance between cities i and j is the smallest cost of a path starting from i and ending at j.
Find the minimum distance from city 1 to all the cities i (1 β€ i β€ n). If there exists no way to go from city 1 to city i, print -1.
<b>Note: </b>
All the edges are bidirectional. There may be multiple edges and self-loops in the input.The first line contains two space separated integers n and m - the number of nodes and edges respectively.
The next m lines contain three-space separated integers x, y, w - representing an edge between x and y with cost w.
<b>Constraints:</b>
1 β€ n β€ 3000
0 β€ m β€ 10000
1 β€ x, y β€ n
1 β€ w β€ 10<sup>9</sup>Output n lines. In the i<sup>th</sup> line, output the minimum distance from city 1 to the i<sup>th</sup> city. If there exists no such path, output -1.Sample Input
6 5
2 4 3
2 3 4
2 1 2
2 5 6
1 5 2
Sample Output
0
2
10
8
2
-1
Explanation:
Shortest path from 1 to 3 is (1->2->3) with total weight= 1*2+2*4=10
Shortest path from 1 to 5 is (1->5) with total weight= 1*2=2
There doesn't exist any path from 1 to 6 so print -1
, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define int long long
const int INF =1e18;
vector<tuple<int, int, int>> adj;
void solve()
{
int n, m;
cin>>n>>m;
// assert(1<=n && n<=3000);
// assert(0<=m && m<=10000);
adj.resize(n);
for(int i = 0;i<m;i++)
{
int x, y, w;
cin>>x>>y>>w;
x--;
y--;
// assert(0<=x && x<n);
// assert(0<=y && y<n);
// assert(1<=w && w<=1e9);
adj.push_back({x, y, w});
adj.push_back({y, x, w});
}
vector<int> dp_old(n, INF);
vector<int> dp_new(n, INF);
dp_old[0] = 0;
for(int i = 1;i<=n;i++)
{
fill(dp_new.begin(), dp_new.end(), INF);
for(auto [x, y,w]:adj)
{
dp_new[y]= min({dp_new[y], dp_old[x] + i * w});
}
for(int j = 0;j<n;j++)
dp_new[j] = min(dp_new[j], dp_old[j]);
swap(dp_new, dp_old);
}
for(int i = 0;i<n;i++)
{
if(dp_old[i] == INF)
dp_old[i] = -1;
cout<<dp_old[i]<<"\n";
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cerr.tie(NULL);
#ifndef ONLINE_JUDGE
if (fopen("INPUT.txt", "r"))
{
freopen("INPUT.txt", "r", stdin);
freopen("OUTPUT.txt", "w", stdout);
}
#endif
solve();
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are n cities in the universe and our beloved Spider-Man is in city 1. He doesn't like to travel by vehicles, so he shot webs forming edges between some pairs of cities. Eventually, there were m edges and each had some cost associated with it.
Spider-Man now defines the cost of a path p from cities p<sub>1</sub> to p<sub>k</sub> as w<sub>1</sub> + 2w<sub>2</sub> + 3w<sub>3</sub> . . . + (k-1)*w<sub>k-1</sub>, where w<sub>i</sub> is the cost of an edge from p<sub>i</sub> to p<sub>i+1</sub>.
Thus, the minimum distance between cities i and j is the smallest cost of a path starting from i and ending at j.
Find the minimum distance from city 1 to all the cities i (1 β€ i β€ n). If there exists no way to go from city 1 to city i, print -1.
<b>Note: </b>
All the edges are bidirectional. There may be multiple edges and self-loops in the input.The first line contains two space separated integers n and m - the number of nodes and edges respectively.
The next m lines contain three-space separated integers x, y, w - representing an edge between x and y with cost w.
<b>Constraints:</b>
1 β€ n β€ 3000
0 β€ m β€ 10000
1 β€ x, y β€ n
1 β€ w β€ 10<sup>9</sup>Output n lines. In the i<sup>th</sup> line, output the minimum distance from city 1 to the i<sup>th</sup> city. If there exists no such path, output -1.Sample Input
6 5
2 4 3
2 3 4
2 1 2
2 5 6
1 5 2
Sample Output
0
2
10
8
2
-1
Explanation:
Shortest path from 1 to 3 is (1->2->3) with total weight= 1*2+2*4=10
Shortest path from 1 to 5 is (1->5) with total weight= 1*2=2
There doesn't exist any path from 1 to 6 so print -1
, I have written this Solution Code: import java.io.*;import java.util.*;import java.math.*;import static java.lang.Math.*;import static java.
util.Map.*;import static java.util.Arrays.*;import static java.util.Collections.*;
import static java.lang.System.*;
public class Main
{
public void tq()throws Exception
{
st=new StringTokenizer(bq.readLine());
int tq=1;
sb=new StringBuilder(2000000);
o:
while(tq-->0)
{
int n=i();
int m=i();
LinkedList<int[]> l[]=new LinkedList[n];
for(int x=0;x<n;x++)l[x]=new LinkedList<>();
for(int x=0;x<m;x++)
{
int a=i()-1;
int b=i()-1;
int c=i();
l[a].add(new int[]{b,c});
l[b].add(new int[]{a,c});
}
long d[]=new long[n];
for(int x=0;x<n;x++)d[x]=maxl;
d[0]=0l;
PriorityQueue<long[]> p=new PriorityQueue<>(5000,(a,b)->a[2]-b[2]<1l?-1:1);
p.add(new long[]{0l,0,0});
while(p.size()>0)
{
long r[]=p.poll();
long di=r[0];
int no=(int)r[1];
long mu=r[2];
for(int e[]:l[no])
{
int node=e[0];
int w=e[1];
long de=di+w*(mu+1);
if(d[node]>de)
{
d[node]=de;
p.add(new long[]{de,node,mu+1});
}
}
}
for(long x:d)
{
sl(x==maxl?-1:x);
}
}
p(sb);
}
int di[][]={{-1,0},{1,0},{0,-1},{0,1}};
int de[][]={{-1,0},{1,0},{0,-1},{0,1},{-1,-1},{1,1},{-1,1},{1,-1}};
long mod=1000000007l;int max=Integer.MAX_VALUE,min=Integer.MIN_VALUE;long maxl=Long.MAX_VALUE, minl=Long.
MIN_VALUE;BufferedReader bq=new BufferedReader(new InputStreamReader(in));StringTokenizer st;
StringBuilder sb;public static void main(String[] a)throws Exception{new Main().tq();}int[] so(int ar[])
{Integer r[]=new Integer[ar.length];for(int x=0;x<ar.length;x++)r[x]=ar[x];sort(r);for(int x=0;x<ar.length;
x++)ar[x]=r[x];return ar;}long[] so(long ar[]){Long r[]=new Long[ar.length];for(int x=0;x<ar.length;x++)
r[x]=ar[x];sort(r);for(int x=0;x<ar.length;x++)ar[x]=r[x];return ar;}
char[] so(char ar[]) {Character
r[]=new Character[ar.length];for(int x=0;x<ar.length;x++)r[x]=ar[x];sort(r);for(int x=0;x<ar.length;x++)
ar[x]=r[x];return ar;}void s(String s){sb.append(s);}void s(int s){sb.append(s);}void s(long s){sb.
append(s);}void s(char s){sb.append(s);}void s(double s){sb.append(s);}void ss(){sb.append(' ');}void sl
(String s){sb.append(s);sb.append("\n");}void sl(int s){sb.append(s);sb.append("\n");}void sl(long s){sb
.append(s);sb.append("\n");}void sl(char s) {sb.append(s);sb.append("\n");}void sl(double s){sb.append(s)
;sb.append("\n");}void sl(){sb.append("\n");}int l(int v){return 31-Integer.numberOfLeadingZeros(v);}
long l(long v){return 63-Long.numberOfLeadingZeros(v);}int sq(int a){return (int)sqrt(a);}long sq(long a)
{return (long)sqrt(a);}long gcd(long a,long b){while(b>0l){long c=a%b;a=b;b=c;}return a;}int gcd(int a,int b)
{while(b>0){int c=a%b;a=b;b=c;}return a;}boolean pa(String s,int i,int j){while(i<j)if(s.charAt(i++)!=
s.charAt(j--))return false;return true;}boolean[] si(int n) {boolean bo[]=new boolean[n+1];bo[0]=true;bo[1]
=true;for(int x=4;x<=n;x+=2)bo[x]=true;for(int x=3;x*x<=n;x+=2){if(!bo[x]){int vv=(x<<1);for(int y=x*x;y<=n;
y+=vv)bo[y]=true;}}return bo;}long mul(long a,long b,long m) {long r=1l;a%=m;while(b>0){if((b&1)==1)
r=(r*a)%m;b>>=1;a=(a*a)%m;}return r;}int i()throws IOException{if(!st.hasMoreTokens())st=new
StringTokenizer(bq.readLine());return Integer.parseInt(st.nextToken());}long l()throws IOException
{if(!st.hasMoreTokens())st=new StringTokenizer(bq.readLine());return Long.parseLong(st.nextToken());}String
s()throws IOException {if (!st.hasMoreTokens())st=new StringTokenizer(bq.readLine());return st.nextToken();}
double d()throws IOException{if(!st.hasMoreTokens())st=new StringTokenizer(bq.readLine());return Double.
parseDouble(st.nextToken());}void p(Object p){out.print(p);}void p(String p){out.print(p);}void p(int p)
{out.print(p);}void p(double p){out.print(p);}void p(long p){out.print(p);}void p(char p){out.print(p);}void
p(boolean p){out.print(p);}void pl(Object p){out.println(p);}void pl(String p){out.println(p);}void pl(int p)
{out.println(p);}void pl(char p){out.println(p);}void pl(double p){out.println(p);}void pl(long p){out.
println(p);}void pl(boolean p)
{out.println(p);}void pl(){out.println();}void s(int a[]){for(int e:a)
{sb.append(e);sb.append(' ');}sb.append("\n");}
void s(long a[])
{for(long e:a){sb.append(e);sb.append(' ')
;}sb.append("\n");}void s(int ar[][]){for(int a[]:ar){for(int e:a){sb.append(e);sb.append(' ');}sb.append
("\n");}}
void s(char a[])
{for(char e:a){sb.append(e);sb.append(' ');}sb.append("\n");}void s(char ar[][])
{for(char a[]:ar){for(char e:a){sb.append(e);sb.append(' ');}sb.append("\n");}}int[] ari(int n)throws
IOException {int ar[]=new int[n];if(!st.hasMoreTokens())st=new StringTokenizer(bq.readLine());for(int x=0;
x<n;x++)ar[x]=Integer.parseInt(st.nextToken());return ar;}int[][] ari(int n,int m)throws
IOException {int ar[][]=new int[n][m];for(int x=0;x<n;x++){if (!st.hasMoreTokens())st=new StringTokenizer
(bq.readLine());for(int y=0;y<m;y++)ar[x][y]=Integer.parseInt(st.nextToken());}return ar;}long[] arl
(int n)throws IOException {long ar[]=new long[n];if(!st.hasMoreTokens()) st=new StringTokenizer(bq.readLine())
;for(int x=0;x<n;x++)ar[x]=Long.parseLong(st.nextToken());return ar;}long[][] arl(int n,int m)throws
IOException {long ar[][]=new long[n][m];for(int x=0;x<n;x++) {if(!st.hasMoreTokens()) st=new
StringTokenizer(bq.readLine());for(int y=0;y<m;y++)ar[x][y]=Long.parseLong(st.nextToken());}return ar;}
String[] ars(int n)throws IOException {String ar[] =new String[n];if(!st.hasMoreTokens())st=new
StringTokenizer(bq.readLine());for(int x=0;x<n;x++)ar[x]=st.nextToken();return ar;}double[] ard
(int n)throws IOException {double ar[] =new double[n];if(!st.hasMoreTokens())st=new StringTokenizer
(bq.readLine());for(int x=0;x<n;x++)ar[x]=Double.parseDouble(st.nextToken());return ar;}double[][] ard
(int n,int m)throws IOException{double ar[][]=new double[n][m];for(int x=0;x<n;x++) {if(!st.hasMoreTokens())
st=new StringTokenizer(bq.readLine());for(int y=0;y<m;y++) ar[x][y]=Double.parseDouble(st.nextToken());}
return ar;}char[] arc(int n)throws IOException{char ar[]=new char[n];if(!st.hasMoreTokens())st=new
StringTokenizer(bq.readLine());for(int x=0;x<n;x++)ar[x]=st.nextToken().charAt(0);return ar;}char[][]
arc(int n,int m)throws IOException {char ar[][]=new char[n][m];for(int x=0;x<n;x++){String s=bq.readLine();
for(int y=0;y<m;y++)ar[x][y]=s.charAt(y);}return ar;}void p(int ar[])
{StringBuilder sb=new StringBuilder
(2*ar.length);for(int a:ar){sb.append(a);sb.append(' ');}out.println(sb);}void p(int ar[][])
{StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);for(int a[]:ar){for(int aa:a){sb.append(aa);
sb.append(' ');}sb.append("\n");}p(sb);}void p(long ar[]){StringBuilder sb=new StringBuilder
(2*ar.length);for(long a:ar){ sb.append(a);sb.append(' ');}out.println(sb);}
void p(long ar[][])
{StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);for(long a[]:ar){for(long aa:a){sb.append(aa);
sb.append(' ');}sb.append("\n");}p(sb);}void p(String ar[]){int c=0;for(String s:ar)c+=s.length()+1;
StringBuilder sb=new StringBuilder(c);for(String a:ar){sb.append(a);sb.append(' ');}out.println(sb);}
void p(double ar[])
{StringBuilder sb=new StringBuilder(2*ar.length);for(double a:ar){sb.append(a);
sb.append(' ');}out.println(sb);}void p
(double ar[][]){StringBuilder sb=new StringBuilder(2*
ar.length*ar[0].length);for(double a[]:ar){for(double aa:a){sb.append(aa);sb.append(' ');}sb.append("\n")
;}p(sb);}void p(char ar[])
{StringBuilder sb=new StringBuilder(2*ar.length);for(char aa:ar){sb.append(aa);
sb.append(' ');}out.println(sb);}void p(char ar[][]){StringBuilder sb=new StringBuilder(2*ar.length*ar[0]
.length);for(char a[]:ar){for(char aa:a){sb.append(aa);sb.append(' ');}sb.append("\n");}p(sb);}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an N*N matrix. Print the elements of the matrix in anticlockwise order (see the sample for better understanding).First line contains N.
N lines follow each containing N space seperated integers.
Constraints:-
2 <= N <= 500
1 <= Mat[i][j] <= 1000Output N*N integers in a single line separated by spaces, which are the elements of the matrix in anti-clockwise order.Sample Input
4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Sample output
1 5 9 13 14 15 16 12 8 4 3 2 6 10 11 7
Explanation:
We start from 1 , go down till 13 and then go right till 16 then go up till 4 , then we go left till 2 then down and so on in anti-clockwise fashion .
Sample Input
3
1 2 3
4 5 6
7 8 9
Sample output
1 4 7 8 9 6 3 2 5
, I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
class Main{
public static void main(String args[])throws IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(in.readLine());
int x, y, start, end, num=n, firstcond, secondcond, thirdcond, fourthcond, flag;
if(n%2!=0)
num++;
num = num/2;
int[][] a = new int[n][n];
for(x=0; x<n; x++){
String nextLine[] = in.readLine().split(" ");
for(y=0; y<n; y++){
a[x][y] = Integer.parseInt(nextLine[y]);
}
}
start = 0;
end = n-1;
while(num>=1){
flag=0;
firstcond = secondcond = thirdcond = fourthcond = 1;
for(x=start, y=start;
(firstcond==1 || secondcond==1 || thirdcond==1 || fourthcond==1) && (x>=start && y>=start && x<=end && y<=end);
){
System.out.print(a[x][y] + " ");
if(firstcond==1){
x++;
if(x==end+1){
firstcond=0;
x--;
y++;
}
}else if(secondcond==1){
y++;
if(y==end+1){
secondcond=0;
y--;
x--;
}
}else if(thirdcond==1){
x--;
if(x==start-1){
if(flag==0)
break;
thirdcond=0;
x++;
y--;
}
flag=1;
}else{
y--;
if(y==start){
fourthcond=0;
x++;
y++;
}
}
}
start++;
end--;
num--;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an N*N matrix. Print the elements of the matrix in anticlockwise order (see the sample for better understanding).First line contains N.
N lines follow each containing N space seperated integers.
Constraints:-
2 <= N <= 500
1 <= Mat[i][j] <= 1000Output N*N integers in a single line separated by spaces, which are the elements of the matrix in anti-clockwise order.Sample Input
4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Sample output
1 5 9 13 14 15 16 12 8 4 3 2 6 10 11 7
Explanation:
We start from 1 , go down till 13 and then go right till 16 then go up till 4 , then we go left till 2 then down and so on in anti-clockwise fashion .
Sample Input
3
1 2 3
4 5 6
7 8 9
Sample output
1 4 7 8 9 6 3 2 5
, I have written this Solution Code: n = int(input())
arr = []
for i in range(n):
j = input().split()
arr.append([int(xx) for xx in j])
def counterClockspiralPrint(m, n, arr) :
k = 0; l = 0
cnt = 0
total = m * n
while (k < m and l < n) :
if (cnt == total) :
break
for i in range(k, m) :
print(arr[i][l], end = " ")
cnt += 1
l += 1
if (cnt == total) :
break
for i in range (l, n) :
print( arr[m - 1][i], end = " ")
cnt += 1
m -= 1
if (cnt == total) :
break
if (k < m) :
for i in range(m - 1, k - 1, -1) :
print(arr[i][n - 1], end = " ")
cnt += 1
n -= 1
if (cnt == total) :
break
if (l < n) :
for i in range(n - 1, l - 1, -1) :
print( arr[k][i], end = " ")
cnt += 1
k += 1
counterClockspiralPrint(n, n, arr), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an N*N matrix. Print the elements of the matrix in anticlockwise order (see the sample for better understanding).First line contains N.
N lines follow each containing N space seperated integers.
Constraints:-
2 <= N <= 500
1 <= Mat[i][j] <= 1000Output N*N integers in a single line separated by spaces, which are the elements of the matrix in anti-clockwise order.Sample Input
4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Sample output
1 5 9 13 14 15 16 12 8 4 3 2 6 10 11 7
Explanation:
We start from 1 , go down till 13 and then go right till 16 then go up till 4 , then we go left till 2 then down and so on in anti-clockwise fashion .
Sample Input
3
1 2 3
4 5 6
7 8 9
Sample output
1 4 7 8 9 6 3 2 5
, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
#define N 1000
void counterClockspiralPrint( int m,
int n,
int arr[][N])
{
int i, k = 0, l = 0;
// k - starting row index
// m - ending row index
// l - starting column index
// n - ending column index
// i - iterator
// initialize the count
int cnt = 0;
// total number of
// elements in matrix
int total = m * n;
while (k < m && l < n)
{
if (cnt == total)
break;
// Print the first column
// from the remaining columns
for (i = k; i < m; ++i)
{
cout << arr[i][l] << " ";
cnt++;
}
l++;
if (cnt == total)
break;
// Print the last row from
// the remaining rows
for (i = l; i < n; ++i)
{
cout << arr[m - 1][i] << " ";
cnt++;
}
m--;
if (cnt == total)
break;
// Print the last column
// from the remaining columns
if (k < m)
{
for (i = m - 1; i >= k; --i)
{
cout << arr[i][n - 1] << " ";
cnt++;
}
n--;
}
if (cnt == total)
break;
// Print the first row
// from the remaining rows
if (l < n)
{
for (i = n - 1; i >= l; --i)
{
cout << arr[k][i] << " ";
cnt++;
}
k++;
}
}
}
int main()
{
int n;
cin>>n;
int arr[n][N];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin>>arr[i][j];
}}
counterClockspiralPrint(n,n, arr);
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an N*N matrix. Print the elements of the matrix in anticlockwise order (see the sample for better understanding).First line contains N.
N lines follow each containing N space seperated integers.
Constraints:-
2 <= N <= 500
1 <= Mat[i][j] <= 1000Output N*N integers in a single line separated by spaces, which are the elements of the matrix in anti-clockwise order.Sample Input
4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Sample output
1 5 9 13 14 15 16 12 8 4 3 2 6 10 11 7
Explanation:
We start from 1 , go down till 13 and then go right till 16 then go up till 4 , then we go left till 2 then down and so on in anti-clockwise fashion .
Sample Input
3
1 2 3
4 5 6
7 8 9
Sample output
1 4 7 8 9 6 3 2 5
, I have written this Solution Code: function printAntiClockWise(mat)
{
let i, k = 0, l = 0;
let m = N;
let n = N;
let cnt = 0, total = m*n;
while(k < m && l < n)
{
if (cnt == total)
break;
// Print the first column
// from the remaining columns
for (i = k; i < m; ++i)
{
process.stdout.write(mat[i][l] + " ");
cnt++;
}
l++;
if (cnt == total)
break;
// Print the last row from
// the remaining rows
for (i = l; i < n; ++i)
{
process.stdout.write(mat[m - 1][i] + " ");
cnt++;
}
m--;
if (cnt == total)
break;
// Print the last column
// from the remaining columns
if (k < m)
{
for (i = m - 1; i >= k; --i)
{
process.stdout.write(mat[i][n - 1] + " ");
cnt++;
}
n--;
}
if (cnt == total)
break;
// Print the first row
// from the remaining rows
if (l < n)
{
for (i = n - 1; i >= l; --i)
{
process.stdout.write(mat[k][i] + " ");
cnt++;
}
k++;
}
}
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array of N integers <b>A<sub>1</sub>, A<sub>2</sub>,... , A<sub>N</sub></b> (1 <= A[i]. length <= 10<sup>5</sup>). You have to find the lone sum of each of these integers.
To find the <b>lone sum</b> of any integer <b>a</b>, following steps are a must:
<ol>
<li>Take an integer b = Sum of digits of x.</li>
<li>If b < 10, lone sum = b and break</li>
<li>If b is at least 10, replace a with b, repeat from step 1.</li>
</ol>
For example:
Lone Sum of 799:
7 + 9 + 9 = 25
2 + 5 = 7.
Therefore, the lone Sum of 799 is 7.
For each integer j from 1 to 9, print the number of integers A<sub>i</sub> (1 <= i <= N) having their lone sum as j.First line of the input contains N, the size of array.
Second line of the input contains N space- separated integers.
<b>Constraints</b>
1 <= N <= 10<sup>5</sup>
1 <= A[i]. length <= 10<sup>5</sup>
Sum of lengths of A[i] over all i from 1 to N doesn't exceed 5*10<sup>5</sup>.Print 9 integers B<sub>1</sub>, B<sub>2</sub>,. , B<sub>9</sub> where B<sub>i</sub> is the number of integers A<sub>i</sub> whose <b>lone sum</b> is i.Sample Input:
5
79752 12793 13471 31973 113
Sample Output:
0 0 1 1 2 0 1 0 0
Explanation:
Lone sum of 79752 = 7 + 9 + 7 + 5 + 2 = 30
= 3 + 0 = <b>3</b>
Lone sum of 12793 = 1 + 2 + 7 + 9 + 3 = 22
= 2 + 2 = <b>4</b>
Lone sum of 13471 = 1 + 3 + 4 + 7 + 1 = 16
= 1 + 6 = <b>7</b>
Lone sum of 31973 = 3 + 1 + 9 + 7 + 3 = 23
= 2 + 3 = <b>5</b>
Lone sum of 113 = 1 + 1 + 3 = <b>5</b>
, 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 long ll;
const int mod = 1e9 + 7;
const int INF = 1e9;
string fun(int sum){
string res = "";
while(sum > 0){
int x = sum%10;
res += (char)(x + '0');
sum /= 10;
}
reverse(all(res));
return res;
}
int lone_sum(string a){
int sum = 0;
for(auto i : a) sum += i - '0';
if(sum < 10) return sum;
else return lone_sum(fun(sum));;
}
void solve() {
int n;
cin >> n;
vector<string> a(n);
vector<int> res(10);
for(auto &i : a) cin >> i;
for(int i = 0; i < n; i++){
res[lone_sum(a[i])]++;
}
for(int i = 1; i <= 9; i++){
if(i > 1){
cout << ' ' << res[i];
}
else cout << res[i];
}
}
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: Nobita likes a number if it is stored in an integer while Doraemon likes it when it is stored in a String. Your task is to write a code so that they can easily convert an integer to a string or a string to an integer whenever they want.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the following functions:-
<b>StringToInt()</b> that takes String S as parameter.
<b>IntToString()</b> that takes the integer N as parameter.
Constraints:-
1 <= (Given Number) <= 100Return an integer in <b>StringToInt()</b> while return a integer integer in <b>IntToString()</b>. The driver code will print "<b>Nice Job</b>" if your code is correct otherwise "<b>Wrong answer</b>".Sample Input:-
5
Sample Output:-
Nice Job
Sample Input:-
12
Sample Output:-
Nice Job, I have written this Solution Code: def StringToInt(a):
return int(a)
def IntToString(a):
return str(a)
if __name__ == "__main__":
n = input()
s = StringToInt(n)
if n == str(s):
a=1
# print("Nice Job")
else:
print("Wrong answer")
quit()
p = IntToString(s)
if s == int(p):
print("Nice Job")
else:
print("Wrong answer"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nobita likes a number if it is stored in an integer while Doraemon likes it when it is stored in a String. Your task is to write a code so that they can easily convert an integer to a string or a string to an integer whenever they want.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the following functions:-
<b>StringToInt()</b> that takes String S as parameter.
<b>IntToString()</b> that takes the integer N as parameter.
Constraints:-
1 <= (Given Number) <= 100Return an integer in <b>StringToInt()</b> while return a integer integer in <b>IntToString()</b>. The driver code will print "<b>Nice Job</b>" if your code is correct otherwise "<b>Wrong answer</b>".Sample Input:-
5
Sample Output:-
Nice Job
Sample Input:-
12
Sample Output:-
Nice Job, I have written this Solution Code: static int StringToInt(String S)
{
return Integer.parseInt(S);
}
static String IntToString(int N){
return String.valueOf(N);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Rohit loves vowels and he likes a string if it contains all the vowels atleast once.
You are given a String S of length N integers. Find minimum length substring of S which contains all vowels atleast once (it may contain other characters too).The first line contains string length and the second line contains the string.
Constraints
1 <= N <= 100000
String contains lowercase english alphabetsThe output should contain only one integer which is the length of minimum length substring containing all vowels. If no such substring exists print -1.Sample input 1:
7
aeiddou
Sample output 1:
7
Sample input 2:
7
daeioud
Sample output 2:
5
Sample input 3:
7
daeiodd
Sample output 3:
-1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static int nextI(String str,int i)
{
char c=str.charAt(i);
return 0;
}
public static boolean vowel(char c)
{
if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u') return true;
else return false;
}
public static void main (String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
String str=br.readLine();
if(n<5)
{
System.out.print(-1);
return;
}
int i=0;
while(i<n && !vowel(str.charAt(i))) ++i;
if(i==n)
{
System.out.print(-1);
return;
}
int min,max;
int len=n;
boolean found=false;
int index,l;
while(i<n)
{
max=-1;
min=n;
if(str.charAt(i)!='a')
{
index=str.indexOf('a',i+1);
if(index==-1) break;
if(index>max) max=index;
if(index<min) min=index;
}
if(str.charAt(i)!='e')
{
index=str.indexOf('e',i+1);
if(index==-1) break;
if(index>max) max=index;
if(index<min) min=index;
}
if(str.charAt(i)!='i')
{
index=str.indexOf('i',i+1);
if(index==-1) break;
if(index>max) max=index;
if(index<min) min=index;
}
if(str.charAt(i)!='o')
{
index=str.indexOf('o',i+1);
if(index==-1) break;
if(index>max) max=index;
if(index<min) min=index;
}
if(str.charAt(i)!='u')
{
index=str.indexOf('u',i+1);
if(index==-1) break;
if(index>max) max=index;
if(index<min) min=index;
}
l=max-i+1;
found=true;
if(l<len) len=l;
index=str.indexOf(str.charAt(i),i+1);
if(index==-1) break;
if(index<min) min=index;
i=min;
}
System.out.print((found)?len:-1);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Rohit loves vowels and he likes a string if it contains all the vowels atleast once.
You are given a String S of length N integers. Find minimum length substring of S which contains all vowels atleast once (it may contain other characters too).The first line contains string length and the second line contains the string.
Constraints
1 <= N <= 100000
String contains lowercase english alphabetsThe output should contain only one integer which is the length of minimum length substring containing all vowels. If no such substring exists print -1.Sample input 1:
7
aeiddou
Sample output 1:
7
Sample input 2:
7
daeioud
Sample output 2:
5
Sample input 3:
7
daeiodd
Sample output 3:
-1, I have written this Solution Code: t=input()
t=int(t)
x=input()
x=x[::-1]
start=0
a=0
e=0
i=0
o=0
u=0
l=[]
n=len(x)
j=0
value=100000
while(j<n):
if(x[j]=='a'):
a+=1
l.append(x[j])
elif x[j]=='e':
e+=1
l.append(x[j])
elif x[j]=='i':
i+=1
l.append(x[j])
elif x[j]=='o':
o+=1
l.append(x[j])
elif x[j]=='u':
u+=1
l.append(x[j])
while(a>=1 and e>=1 and i>=1 and o>=1 and u>=1):
if(value>(j-start+1)):
value=j-start+1
if(x[start]=='a'):
a-=1
elif(x[start]=='e'):
e-=1
elif(x[start]=='i'):
i-=1
elif(x[start]=='o'):
o-=1
elif(x[start]=='u'):
u-=1
if(l):
l.pop(0)
start=start+1
j+=1
if(value==100000):
print("-1")
else:
print (value), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Rohit loves vowels and he likes a string if it contains all the vowels atleast once.
You are given a String S of length N integers. Find minimum length substring of S which contains all vowels atleast once (it may contain other characters too).The first line contains string length and the second line contains the string.
Constraints
1 <= N <= 100000
String contains lowercase english alphabetsThe output should contain only one integer which is the length of minimum length substring containing all vowels. If no such substring exists print -1.Sample input 1:
7
aeiddou
Sample output 1:
7
Sample input 2:
7
daeioud
Sample output 2:
5
Sample input 3:
7
daeiodd
Sample output 3:
-1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
t=1;
while(t--){
int n;
cin>>n;
string s;
cin>>s;
map<char,int> m;
m['a']=0;
m['e']=0;
m['i']=0;
m['o']=0;
m['u']=0;
int cnt=0, ans=INT_MAX,j=0;
for(int i=0;i<n;i++){
if(m.find(s[i])!=m.end()){
if(m[s[i]]==0){cnt++;}
m[s[i]]++;
}
if(cnt==5){
ans=min(ans,i-j+1);
while(1){
if(m.find(s[j])!=m.end()){m[s[j]]--;
if(m[s[j]]==0){j++;
break;}
}
j++;
ans=min(ans,i-j+1);
}
cnt--;
}
}
if(ans==INT_MAX){cout<<-1;return 0;}
cout<<ans<<endl;}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to check whether a number is positive, negative or zero using switch case.The first line of the input contains the number
<b>Constraints</b>
-10<sup>9</sup> ≤ n ≤ 10<sup>9</sup>Print the single line wether it's "Positive", "Negative" or "Zero"Sample Input :
13
Sample Output :
Positive
Sample Input :
-13
Sample Output :
Negative, 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 s=br.readLine().toString();
int n=Integer.parseInt(s);
int ch=0;
if(n>0){
ch=1;
}
else if(n<0) ch=-1;
switch(ch){
case 1: System.out.println("Positive");break;
case 0: System.out.println("Zero");break;
case -1: System.out.println("Negative");break;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to check whether a number is positive, negative or zero using switch case.The first line of the input contains the number
<b>Constraints</b>
-10<sup>9</sup> ≤ n ≤ 10<sup>9</sup>Print the single line wether it's "Positive", "Negative" or "Zero"Sample Input :
13
Sample Output :
Positive
Sample Input :
-13
Sample Output :
Negative, I have written this Solution Code: n = input()
if '-' in list(n):
print('Negative')
elif int(n) == 0 :
print('Zero')
else:
print('Positive'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to check whether a number is positive, negative or zero using switch case.The first line of the input contains the number
<b>Constraints</b>
-10<sup>9</sup> ≤ n ≤ 10<sup>9</sup>Print the single line wether it's "Positive", "Negative" or "Zero"Sample Input :
13
Sample Output :
Positive
Sample Input :
-13
Sample Output :
Negative, I have written this Solution Code: #include <stdio.h>
int main()
{
int num;
scanf("%d", &num);
switch (num > 0)
{
// Num is positive
case 1:
printf("Positive");
break;
// Num is either negative or zero
case 0:
switch (num < 0)
{
case 1:
printf("Negative");
break;
case 0:
printf("Zero");
break;
}
break;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Pree says he stole Daenerys' dragons, and would return them to Daenerys only if she can pair the dragons in a peculiar way.
There are N (N is even) dragons, the strength of i<sup>th</sup> dragon is A<sub>i</sub>. She needs to create N/2 pairs of the dragons. The strength of the dragon pair is the sum of the strengths of dragons in the pair. She needs to pair them in such a way that the difference between the strength of dragon pair with maximum strength and the strength of the dragon pair with minimum strength is minimised.
Now, you need to find the minimum difference in strengths if she has paired them correctly.The first line of the input contains an integer N, the number of dragons.
The second line of the input contains N integers, the strengths of the dragons.
Constraints
1 <= N <= 200000 (so many dragons, huh)
1 <= A<sub>i</sub> <= 10<sup>9</sup> for all values of i
N is divisible by 2Output a single integer, the answer to the problem.Sample Input
4
1 2 1 2
Sample Output
0
Explanation
Daenerys pairs 1st and the 2nd dragons together; the 3rd and the 4th dragon together
Sample Input
6
2 3 2 4 5 1
Sample Output
1, I have written this Solution Code: import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
import java.util.StringTokenizer;
public 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();
PrintWriter pw = new PrintWriter(System.out);
int n=sc.nextInt();
long arr[]=new long[n];
for(int i=0;i<n;i++)
{
arr[i]=sc.nextLong();
}
Arrays.sort(arr);
long min=Long.MAX_VALUE;
long max=Long.MIN_VALUE;
for(int i=0;i<n/2;i++)
{
min=Math.min(min,arr[n-i-1]+arr[i]);
max=Math.max(max,arr[n-i-1]+arr[i]);
}
System.out.println(max-min);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Pree says he stole Daenerys' dragons, and would return them to Daenerys only if she can pair the dragons in a peculiar way.
There are N (N is even) dragons, the strength of i<sup>th</sup> dragon is A<sub>i</sub>. She needs to create N/2 pairs of the dragons. The strength of the dragon pair is the sum of the strengths of dragons in the pair. She needs to pair them in such a way that the difference between the strength of dragon pair with maximum strength and the strength of the dragon pair with minimum strength is minimised.
Now, you need to find the minimum difference in strengths if she has paired them correctly.The first line of the input contains an integer N, the number of dragons.
The second line of the input contains N integers, the strengths of the dragons.
Constraints
1 <= N <= 200000 (so many dragons, huh)
1 <= A<sub>i</sub> <= 10<sup>9</sup> for all values of i
N is divisible by 2Output a single integer, the answer to the problem.Sample Input
4
1 2 1 2
Sample Output
0
Explanation
Daenerys pairs 1st and the 2nd dragons together; the 3rd and the 4th dragon together
Sample Input
6
2 3 2 4 5 1
Sample Output
1, I have written this Solution Code: n = int(input())
bruh = input().strip().split(" ")
for i in range(len(bruh)):
bruh[i] = int(bruh[i])
bruh.sort()
maxSum = 0
minSum = 100000000000000000000
for i in range(len(bruh)//2):
add = bruh[i] + bruh[-(i+1)]
if add > maxSum:
maxSum = add
if add < minSum:
minSum = add
print(maxSum - minSum), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Pree says he stole Daenerys' dragons, and would return them to Daenerys only if she can pair the dragons in a peculiar way.
There are N (N is even) dragons, the strength of i<sup>th</sup> dragon is A<sub>i</sub>. She needs to create N/2 pairs of the dragons. The strength of the dragon pair is the sum of the strengths of dragons in the pair. She needs to pair them in such a way that the difference between the strength of dragon pair with maximum strength and the strength of the dragon pair with minimum strength is minimised.
Now, you need to find the minimum difference in strengths if she has paired them correctly.The first line of the input contains an integer N, the number of dragons.
The second line of the input contains N integers, the strengths of the dragons.
Constraints
1 <= N <= 200000 (so many dragons, huh)
1 <= A<sub>i</sub> <= 10<sup>9</sup> for all values of i
N is divisible by 2Output a single integer, the answer to the problem.Sample Input
4
1 2 1 2
Sample Output
0
Explanation
Daenerys pairs 1st and the 2nd dragons together; the 3rd and the 4th dragon together
Sample Input
6
2 3 2 4 5 1
Sample Output
1, 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(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 pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
int n; cin>>n;
vector<int> v(n);
For(i, 0, n){
cin>>v[i];
}
sort(all(v));
vector<int> cur;
For(i, 0, n/2){
cur.pb(v[i]+v[n-i-1]);
}
sort(all(cur));
cout<<cur[n/2-1]-cur[0];
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
cout<<"\n";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the simple interest for given principal amount P, time Tm(in years) and rate R.<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>SimpleInterest()</b> that takes the principal amount P, rate R, and time Tm as a parameter.
Constraints:
1 <= P <= 10^3
1 <= Tm <= 20
1 <= R <= 20Return the floor value of the simple interest i.e. interest in integer format.Input:
42 15 8
Output:
50
Explanation:
Testcase 1: Simple interest of given principal amount 42, in 8 years at a 15% rate of interest is 50., I have written this Solution Code: import math
p,t,r = [int(x) for x in input().split()]
res=p*t*r
print(math.floor(res/100)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the simple interest for given principal amount P, time Tm(in years) and rate R.<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>SimpleInterest()</b> that takes the principal amount P, rate R, and time Tm as a parameter.
Constraints:
1 <= P <= 10^3
1 <= Tm <= 20
1 <= R <= 20Return the floor value of the simple interest i.e. interest in integer format.Input:
42 15 8
Output:
50
Explanation:
Testcase 1: Simple interest of given principal amount 42, in 8 years at a 15% rate of interest is 50., I have written this Solution Code: static int SimpleInterest(int P, int R, int Tm){
return (P*Tm*R)/100;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Complete the function <code>promiseMe</code>
Such that it takes a number as the first argument (time) and a string as the second argument(data).
It returns a promise which resolves after time milliseconds and data is returned.
Note:- You only have to implement the function, in the example it
shows your implemented question will be run.Function should take number as first argument and data to be returned as second.Resolves to the data given as inputpromiseMe(200, 'hi').then(data=>{
console.log(data) // prints hi
}), I have written this Solution Code: function promiseMe(number, dat) {
return new Promise((res,rej)=>{
setTimeout(()=>{
res(dat)
},number)
})
// return the output using return keyword
// do not console.log it
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a linked list consisting of N nodes and an integer K, your task is to delete the Kth node from the end 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>deleteElement()</b> that takes head node and K as parameter.
Constraints:
1 <=K<=N<= 1000
1 <=Node.data<= 1000Return the head of the modified linked listInput 1:
5 3
1 2 3 4 5
Output 1:
1 2 4 5
Explanation:
After deleting 3rd node from the end of the linked list, 3 will be deleted and the list will be as 1, 2, 4, 5.
Input 2:-
5 5
8 1 8 3 6
Output 2:-
1 8 3 6 , I have written this Solution Code: public static Node deleteElement(Node head,int k) {
int cnt=0;
Node temp=head;
while(temp!=null){
cnt++;
temp=temp.next;
}
temp=head;
k=cnt-k;
if(k==0){head=head.next; return head;}
temp=head;
cnt=0;
while(cnt!=k-1){
temp=temp.next;
cnt++;
}
temp.next=temp.next.next;
return head;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Take an integer as input and print it.The first line contains integer as input.
<b>Constraints</b>
1 <= N <= 10Print the input integer in a single lineSample Input:-
2
Sample Output:-
2
Sample Input:-
4
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 printVariable(int variable){
System.out.println(variable);
}
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
printVariable(num);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer, print whether that integer is a prime number or not.First line of input contains an integer T, showing the number of test cases. Every test case is a single integer A.
Constraints
1 <= T <= 100
1 <= A <= 10^8If the given integer is prime, print 'Yes', else print 'No'.Sample Input
3
5
9
13
Output
Yes
No
Yes, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
try{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int testcase = Integer.parseInt(br.readLine());
for(int t=0;t<testcase;t++){
int num = Integer.parseInt(br.readLine().trim());
if(num==1)
System.out.println("No");
else if(num<=3)
System.out.println("Yes");
else{
if((num%2==0)||(num%3==0))
System.out.println("No");
else{
int flag=0;
for(int i=5;i*i<=num;i+=6){
if(((num%i)==0)||(num%(i+2)==0)){
System.out.println("No");
flag=1;
break;
}
}
if(flag==0)
System.out.println("Yes");
}
}
}
}catch (Exception e) {
System.out.println("I caught: " + e);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer, print whether that integer is a prime number or not.First line of input contains an integer T, showing the number of test cases. Every test case is a single integer A.
Constraints
1 <= T <= 100
1 <= A <= 10^8If the given integer is prime, print 'Yes', else print 'No'.Sample Input
3
5
9
13
Output
Yes
No
Yes, I have written this Solution Code: t=int(input())
for i in range(t):
number = int(input())
if number > 1:
i=2
while i*i<=number:
if (number % i) == 0:
print("No")
break
i+=1
else:
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, print whether that integer is a prime number or not.First line of input contains an integer T, showing the number of test cases. Every test case is a single integer A.
Constraints
1 <= T <= 100
1 <= A <= 10^8If the given integer is prime, print 'Yes', else print 'No'.Sample Input
3
5
9
13
Output
Yes
No
Yes, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
long long n,k;
cin>>n;
long x=sqrt(n);
int cnt=0;
vector<int> v;
for(long long i=2;i<=x;i++){
if(n%i==0){
cout<<"No"<<endl;
goto f;
}}
cout<<"Yes"<<endl;
f:;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two sorted array your task is to merge these two arrays into a single array such that the merged array is also sortedFirst line contain two integers N and M the size of arrays
Second line contains N separated integers the elements of first array
Third line contains M separated integers elements of second array
<b>Constraints:-</b>
1<=N,M<=10<sup>4</sup>
1<=arr1[], arr2[] <=10<sup>5</sup>Output the merged arraySample Input:-
3 4
1 4 7
1 3 3 9
Sample Output:-
1 1 3 3 4 7 9
, I have written this Solution Code: n1,m1=input().split()
n=int(n1)
m=int(m1)
l1=list(map(int,input().strip().split()))
l2=list(map(int,input().strip().split()))
i,j=0,0
while i<n and j<m:
if l1[i]<=l2[j]:
print(l1[i],end=" ")
i+=1
else:
print(l2[j],end=" ")
j+=1
for a in range(i,n):
print(l1[a],end=" ")
for b in range(j,m):
print(l2[b],end=" "), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two sorted array your task is to merge these two arrays into a single array such that the merged array is also sortedFirst line contain two integers N and M the size of arrays
Second line contains N separated integers the elements of first array
Third line contains M separated integers elements of second array
<b>Constraints:-</b>
1<=N,M<=10<sup>4</sup>
1<=arr1[], arr2[] <=10<sup>5</sup>Output the merged arraySample Input:-
3 4
1 4 7
1 3 3 9
Sample Output:-
1 1 3 3 4 7 9
, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define max1 10000001
int main(){
int n,m;
cin>>n>>m;
int a[n];
int b[m];
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<m;i++){
cin>>b[i];
}
int c[n+m];
int i=0,j=0,k=0;
while(i!=n && j!=m){
if(a[i]<b[j]){c[k]=a[i];k++;i++;}
else{c[k]=b[j];j++;k++;}
}
while(i!=n){
c[k]=a[i];
k++;i++;
}
while(j!=m){
c[k]=b[j];
k++;j++;
}
for(i=0;i<n+m;i++){
cout<<c[i]<<" ";
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two sorted array your task is to merge these two arrays into a single array such that the merged array is also sortedFirst line contain two integers N and M the size of arrays
Second line contains N separated integers the elements of first array
Third line contains M separated integers elements of second array
<b>Constraints:-</b>
1<=N,M<=10<sup>4</sup>
1<=arr1[], arr2[] <=10<sup>5</sup>Output the merged arraySample Input:-
3 4
1 4 7
1 3 3 9
Sample Output:-
1 1 3 3 4 7 9
, 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);
int n = sc.nextInt();
int m = sc.nextInt();
int a[] = new int[n];
int b[] = new int[m];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
for(int i=0;i<m;i++){
b[i]=sc.nextInt();
}
int c[]=new int[n+m];
int i=0,j=0,k=0;
while(i!=n && j!=m){
if(a[i]<b[j]){c[k]=a[i];k++;i++;}
else{c[k]=b[j];j++;k++;}
}
while(i!=n){
c[k]=a[i];
k++;i++;
}
while(j!=m){
c[k]=b[j];
k++;j++;
}
for(i=0;i<n+m;i++){
System.out.print(c[i]+" ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: When learning a new language, we first learn to output some messages. Here, we will start with the famous <b>"Hello World"</b> message. Now, here you are given a function to complete. <i>Don't worry about the ins and outs of functions, <b>just add the printing command to print "Hello World", </b></i>.your task is to just print "Hello World", without the quotes.Hello WorldHello World must be printed., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
System.out.print("Hello World");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: When learning a new language, we first learn to output some messages. Here, we will start with the famous <b>"Hello World"</b> message. Now, here you are given a function to complete. <i>Don't worry about the ins and outs of functions, <b>just add the printing command to print "Hello World", </b></i>.your task is to just print "Hello World", without the quotes.Hello WorldHello World must be printed., I have written this Solution Code: def print_fun():
print ("Hello World")
def main():
print_fun()
if __name__ == '__main__':
main(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a 2D matrix of size [M, N], Q number of queries. In each query, you will be given a number X to check whether it is present in the matrix or not.The first line contains three integers M(number of rows), N(Number of columns), and Q(number of queries)
Next M lines contain N integers which are the elements of the matrix.
Next, Q lines will contain a single integer X.
Constraints:-
1<=M,N<=1000
1<=Q<=10000
1<=X, Arr[i]<=1000000000For each query, in a new line print "Yes" if the element is present in matrix or print "No" if the element is absent.Input:-
3 3 2
1 2 3
5 6 7
8 9 10
7
11
Output:-
Yes
No
Input:-
3 4 4
4 8 11 14
15 54 45 47
1 2 3 4
5
15
45
26
Output:-
No
Yes
Yes
No, I have written this Solution Code: import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
public static void main (String[] args) {
// Your code here
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
int n = sc.nextInt();
int q = sc.nextInt();
int mat[] = new int[m*n];
int matSize = m*n;
for(int i = 0; i < m*n; i++)
{
int ele = sc.nextInt();
mat[i] = ele;
}
Arrays.sort(mat);
for(int i = 1; i <= q; i++)
{
int qs = sc.nextInt();
System.out.println(isPresent(mat, matSize, qs));
}
}
static String isPresent(int mat[], int size, int ele)
{
int l = 0, h = size-1;
while(l <= h)
{
int mid = l + (h-l)/2;
if(mat[mid] == ele)
return "Yes";
else if(mat[mid] > ele)
h = mid - 1;
else l = mid+1;
}
return "No";
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a 2D matrix of size [M, N], Q number of queries. In each query, you will be given a number X to check whether it is present in the matrix or not.The first line contains three integers M(number of rows), N(Number of columns), and Q(number of queries)
Next M lines contain N integers which are the elements of the matrix.
Next, Q lines will contain a single integer X.
Constraints:-
1<=M,N<=1000
1<=Q<=10000
1<=X, Arr[i]<=1000000000For each query, in a new line print "Yes" if the element is present in matrix or print "No" if the element is absent.Input:-
3 3 2
1 2 3
5 6 7
8 9 10
7
11
Output:-
Yes
No
Input:-
3 4 4
4 8 11 14
15 54 45 47
1 2 3 4
5
15
45
26
Output:-
No
Yes
Yes
No, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
#define N 1000000
long a[N];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,m,q;
cin>>n>>m>>q;
n=n*m;
long long sum=0,sum1=0;
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
while(q--){
long x;
cin>>x;
int l=0;
int r=n-1;
while (r >= l) {
int mid = l + (r - l) / 2;
if (a[mid] == x) {
cout<<"Yes"<<endl;goto f;}
if (a[mid] > x)
{
r=mid-1;
}
else {l=mid+1;
}
}
cout<<"No"<<endl;
f:;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nutan and Tusla are both students at Newton School. They are both among the best students in the class. In order to know who is better among them, a game was organised. The game consisted of L rounds, where L is an odd integer. The student winning more rounds than the other was declared the winner.
You would be given a string of odd length L in which each character is 'N' or 'T'. If the i<sup>th</sup> character is 'N', then the i<sup>th</sup> round was won by Nutan, else if the character is 'T' it was won by Tusla. Print "Nutan'' if Nutan has won more rounds than Tusla, else print "Tusla'' if Tusla has won more rounds than Nutan.
Note: You have to print everything without quotes.The first line of the input contains a single integer L β the number of rounds (1 ≤ L ≤ 100 and L is odd).
The second line contains a string S of length L. Each character of S is either 'N' or 'T'.Print "Nutan" or "Tusla" according to the input.Sample Input:
3
NNT
Sample Output:
Nutan
Explanation:
Nutan has won two games while Tusla has only won a single game, so the overall winner is Nutan., I have written this Solution Code: import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import static java.lang.System.out;
public 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 reader = new FastReader();
int n = reader.nextInt();
String S = reader.next();
int ncount = 0;
int tcount = 0;
for (char c : S.toCharArray()) {
if (c == 'N') ncount++;
else tcount++;
}
if (ncount > tcount) {
out.print("Nutan\n");
} else {
out.print("Tusla\n");
}
out.flush();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nutan and Tusla are both students at Newton School. They are both among the best students in the class. In order to know who is better among them, a game was organised. The game consisted of L rounds, where L is an odd integer. The student winning more rounds than the other was declared the winner.
You would be given a string of odd length L in which each character is 'N' or 'T'. If the i<sup>th</sup> character is 'N', then the i<sup>th</sup> round was won by Nutan, else if the character is 'T' it was won by Tusla. Print "Nutan'' if Nutan has won more rounds than Tusla, else print "Tusla'' if Tusla has won more rounds than Nutan.
Note: You have to print everything without quotes.The first line of the input contains a single integer L β the number of rounds (1 ≤ L ≤ 100 and L is odd).
The second line contains a string S of length L. Each character of S is either 'N' or 'T'.Print "Nutan" or "Tusla" according to the input.Sample Input:
3
NNT
Sample Output:
Nutan
Explanation:
Nutan has won two games while Tusla has only won a single game, so the overall winner is Nutan., I have written this Solution Code: n = int(input())
s = input()
a1 = s.count('N')
a2 = s.count('T')
if(a1 > a2):
print("Nutan")
else:
print('Tusla'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nutan and Tusla are both students at Newton School. They are both among the best students in the class. In order to know who is better among them, a game was organised. The game consisted of L rounds, where L is an odd integer. The student winning more rounds than the other was declared the winner.
You would be given a string of odd length L in which each character is 'N' or 'T'. If the i<sup>th</sup> character is 'N', then the i<sup>th</sup> round was won by Nutan, else if the character is 'T' it was won by Tusla. Print "Nutan'' if Nutan has won more rounds than Tusla, else print "Tusla'' if Tusla has won more rounds than Nutan.
Note: You have to print everything without quotes.The first line of the input contains a single integer L β the number of rounds (1 ≤ L ≤ 100 and L is odd).
The second line contains a string S of length L. Each character of S is either 'N' or 'T'.Print "Nutan" or "Tusla" according to the input.Sample Input:
3
NNT
Sample Output:
Nutan
Explanation:
Nutan has won two games while Tusla has only won a single game, so the overall winner is Nutan., I have written this Solution Code: //Author: Xzirium
//Time and Date: 02:18:28 24 March 2022
//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()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//-----------------------------------------------------------------------------------------------------------//
READV(N);
string S;
cin>>S;
ll n=0,t=0;
FORI(i,0,N)
{
if(S[i]=='N')
{
n++;
}
else if(S[i]=='T')
{
t++;
}
}
if(n>t)
{
cout<<"Nutan"<<endl;
}
else
{
cout<<"Tusla"<<endl;
}
//-----------------------------------------------------------------------------------------------------------//
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: void fizzbuzz(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){cout<<"FizzBuzz"<<" ";}
else if(i%5==0){cout<<"Buzz ";}
else if(i%3==0){cout<<"Fizz ";}
else{cout<<i<<" ";}
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, 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);
int x= sc.nextInt();
fizzbuzz(x);
}
static void fizzbuzz(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){System.out.print("FizzBuzz ");}
else if(i%5==0){System.out.print("Buzz ");}
else if(i%3==0){System.out.print("Fizz ");}
else{System.out.print(i+" ");}
}
}
}, 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.