Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: Newton is highly ambitious, and he currently has 10 rupees. He goes to the casino and plays against an infinitely rich man (never ending money) in order to win huge money.
The rules of the game are super simple. There are N turns and the following procedure is followed in each turn.
<ul>
<li>If one of the player has 0 money, nothing happens.
<li> Else, the losing player loses 1 rupee and the winning player wins 1 rupee.
</ul>
The probability of Newton winning in any turn is P/Q. Find the expected money he would have, if N is 5000<sup>5000<sup>5000</sup></sup>.The first and the only line of input contains two integers P and Q.
Constraints
1 <= P <= Q <= 1000000If the expected value is greater than 10^18, output 10^18, else output floor(expected value).Sample Input
1 1000000
Sample Output
0
Explanation
Given the probability of Newton winning is 0.000001.
It can be proved that the floor of expected money he has after infinite number of turns is 0., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define 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 p, q; cin>>p>>q;
q = q-p;
if(p < q){
cout<<0;
}
else if(p==q)
cout<<10;
else{
cout<<1000000000000000000LL;
}
}
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: Given a Doubly linked list consisting of <b>N</b> nodes and given a number <b>K</b>. The 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 the position K as parameter.
Constraints:
1 <=K<=N<= 1000
1 <=value<= 1000Return the head of the modified Doubly linked listInput:
5 3
1 2 3 4 5
Output:
1 2 4 5
Explanation:
After deleting 3rd node from the end of the linked list, 3 will be deleted and the list will become 1, 2, 4, 5., 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;
}
k=cnt-k;
if(k==0){head=head.next;
head.prev=null;
return head;}
temp=head;
int i=0;
while(i!=k-1){
temp=temp.next;
i++;
}
temp.next=temp.next.next;
if(k!=cnt-1){temp.next.prev=temp;}
return head;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given head which is a reference node to a doubly- linked list of integers. Complete the function <b>sortedInsertion</b> which inserts value in sorted doubly linked list such that the list is sorted after insertion.User task:
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>sortedInsertion</b> that takes the head of the linked list and the value to be inserted as parameter.
Constraints:
1 <= Number of nodes <= 10000.
Data at node <= 100000The function need not return anything.Sample Input 1:-
3 2
1 2 3
Sample Output 1:-
1 2 2 3
Explanation:
We will add 2 at index 2. So, our list is sorted and we successfully inserted the value 2.
Sample Input 2:-
2 0
1 2
Sample Output 2:-
0 1 2
Explanation:
We will insert 0 at index 0. So, our list is sorted and we successfully inserted the value 0., I have written this Solution Code: static Node sortedInsertion(Node head, Node newNode)
{
Node current;
if (head == null)
head = newNode;
else if (head.data >= newNode.data)
{
newNode.next = head;
newNode.next.prev = newNode;
head = newNode;
}
else
{
current = head;
while (current.next != null &&
current.next.data < newNode.data)
current = current.next;
newNode.next = current.next;
if (current.next != null)
newNode.next.prev = newNode;
current.next = newNode;
newNode.prev = current;
}
return head;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement Selection Sort on a given array, and make it sorted.First line of the input contains an integer, N, which denotes the length of the array. Next N inputs are elements of the array that is to be sorted in ascending order.
Constraints
1<=N<=1000
-10000<=Arr[i]<=10000Sorted output where each element is space separatedSample Input:
3
3 1 2
Sample Output:
1 2 3, I have written this Solution Code: // arr is unsorted array
// n is the number of elements in the array
function selectionSort(arr, n) {
// write code here
// do not console.log the answer
// return sorted array
return arr.sort((a, b) => a - b)
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement Selection Sort on a given array, and make it sorted.First line of the input contains an integer, N, which denotes the length of the array. Next N inputs are elements of the array that is to be sorted in ascending order.
Constraints
1<=N<=1000
-10000<=Arr[i]<=10000Sorted output where each element is space separatedSample Input:
3
3 1 2
Sample Output:
1 2 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());
String[] str = br.readLine().split(" ");
int a[] = new int[n];
for(int i=0; i<n; i++){
a[i] = Integer.parseInt(str[i]);
}
for(int i=0; i<n-1; i++){
for(int j=i+1; j<n; j++){
if(a[i]>a[j]){
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
for(int i=0; i<n; i++){
System.out.print(a[i]+" ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement Selection Sort on a given array, and make it sorted.First line of the input contains an integer, N, which denotes the length of the array. Next N inputs are elements of the array that is to be sorted in ascending order.
Constraints
1<=N<=1000
-10000<=Arr[i]<=10000Sorted output where each element is space separatedSample Input:
3
3 1 2
Sample Output:
1 2 3, I have written this Solution Code: def selectionSort(arr):
arr.sort()
return arr
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement Selection Sort on a given array, and make it sorted.First line of the input contains an integer, N, which denotes the length of the array. Next N inputs are elements of the array that is to be sorted in ascending order.
Constraints
1<=N<=1000
-10000<=Arr[i]<=10000Sorted output where each element is space separatedSample Input:
3
3 1 2
Sample Output:
1 2 3, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
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: 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: Your friend and you took a true/false exam of n questions. You know your answers, your friend’s
answers, and that your friend got k questions correct.
Compute the maximum number of questions you could have gotten correctly.The first line of input contains a single integer k.
The second line contains a string of n (1 ≤ n ≤ 1000) characters, the answers you wrote down.
Each letter is either a ‘T’ or an ‘F’.
The third line contains a string of n characters, the answers your friend wrote down. Each letter
is either a ‘T’ or an ‘F’.
The input will satisfy 0 ≤ k ≤ n.Print, on one line, the maximum number of questions you could have gotten correctly.Sample Input
3
FTFFF
TFTTT
Sample Output
2, 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 k = Integer.parseInt(br.readLine());
String me = br.readLine();
String myFriend = br.readLine();
int N = me.length();
int commonAns = 0;
for(int i=0; i<N; i++) {
if(me.charAt(i) == myFriend.charAt(i) ) commonAns++;
}
int ans = Math.min(k, commonAns) + Math.min(N - k, N - commonAns);
System.out.println(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Your friend and you took a true/false exam of n questions. You know your answers, your friend’s
answers, and that your friend got k questions correct.
Compute the maximum number of questions you could have gotten correctly.The first line of input contains a single integer k.
The second line contains a string of n (1 ≤ n ≤ 1000) characters, the answers you wrote down.
Each letter is either a ‘T’ or an ‘F’.
The third line contains a string of n characters, the answers your friend wrote down. Each letter
is either a ‘T’ or an ‘F’.
The input will satisfy 0 ≤ k ≤ n.Print, on one line, the maximum number of questions you could have gotten correctly.Sample Input
3
FTFFF
TFTTT
Sample Output
2, I have written this Solution Code: k = int(input())
m = 0
a = list(map(str,input()))
b = list(map(str,input()))
#print(a,b)
n = len(b)
for i in range(n):
if a[i] == b[i]:
m += 1
if k >= m :
print(n-k+m)
else:
print(n-m+k), 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 roots of a quadratic equation.
<b>Note</b>: Try to do it using Switch Case.
<b>Quadratic equations</b> are the polynomial equations of degree 2 in one variable of type f(x) = ax<sup>2</sup> + bx + c = 0 where a, b, c, ∈ R and a ≠0. It is the general form of a quadratic equation where 'a' is called the leading coefficient and 'c' is called the absolute term of f (x).The first line of the input contains the three integer values a, b, and c of equation ax^2 + bx + c.
<b>Constraints</b>
1 ≤ a, b, c ≤ 50Print the two roots in two different lines and for imaginary roots print real and imaginary part of one root with (+/- and i )sign in between in one line and other in next line. For clarity see sample Output 2.
<b>Note</b> Imaginary roots can also be there and roots are considered upto 2 decimal places.Sample Input 1 :
4 -2 -10
Sample Output 2 :
1.85
-1.35
Sample Input 2 :
2 1 10
Sample Output 2:
-0.25+i2.22
-0.25-i2.22, 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();
String[] str = s.split(" ");
float a=Float.parseFloat(str[0]);
float b=Float.parseFloat(str[1]);
float c=Float.parseFloat(str[2]);
float div = (float)(b*b-4*a*c);
if(div>0.0){
float alpha= (-b+(float)Math.sqrt(div))/(2*a);
float beta= (-b-(float)Math.sqrt(div))/(2*a);
System.out.printf("%.2f\n",alpha);
System.out.printf("%.2f",beta);
}
else{
float rp=-b/(2*a);
float ip=(float)Math.sqrt(-div)/(2*a);
System.out.printf("%.2f+i%.2f\n",rp,ip);
System.out.printf("%.2f-i%.2f\n",rp,ip);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the roots of a quadratic equation.
<b>Note</b>: Try to do it using Switch Case.
<b>Quadratic equations</b> are the polynomial equations of degree 2 in one variable of type f(x) = ax<sup>2</sup> + bx + c = 0 where a, b, c, ∈ R and a ≠0. It is the general form of a quadratic equation where 'a' is called the leading coefficient and 'c' is called the absolute term of f (x).The first line of the input contains the three integer values a, b, and c of equation ax^2 + bx + c.
<b>Constraints</b>
1 ≤ a, b, c ≤ 50Print the two roots in two different lines and for imaginary roots print real and imaginary part of one root with (+/- and i )sign in between in one line and other in next line. For clarity see sample Output 2.
<b>Note</b> Imaginary roots can also be there and roots are considered upto 2 decimal places.Sample Input 1 :
4 -2 -10
Sample Output 2 :
1.85
-1.35
Sample Input 2 :
2 1 10
Sample Output 2:
-0.25+i2.22
-0.25-i2.22, I have written this Solution Code: import math
a,b,c = map(int, input().split(' '))
disc = (b ** 2) - (4*a*c)
sq = disc ** 0.5
if disc > 0:
print("{:.2f}".format((-b + sq)/(2*a)))
print("{:.2f}".format((-b - sq)/(2*a)))
elif disc == 0:
print("{:.2f}".format(-b/(2*a)))
elif disc < 0:
r1 = complex((-b + sq)/(2*a))
r2 = complex((-b - sq)/(2*a))
print("{:.2f}+i{:.2f}".format(r1.real, abs(r1.imag)))
print("{:.2f}-i{:.2f}".format(r2.real, abs(r2.imag))), 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 roots of a quadratic equation.
<b>Note</b>: Try to do it using Switch Case.
<b>Quadratic equations</b> are the polynomial equations of degree 2 in one variable of type f(x) = ax<sup>2</sup> + bx + c = 0 where a, b, c, ∈ R and a ≠0. It is the general form of a quadratic equation where 'a' is called the leading coefficient and 'c' is called the absolute term of f (x).The first line of the input contains the three integer values a, b, and c of equation ax^2 + bx + c.
<b>Constraints</b>
1 ≤ a, b, c ≤ 50Print the two roots in two different lines and for imaginary roots print real and imaginary part of one root with (+/- and i )sign in between in one line and other in next line. For clarity see sample Output 2.
<b>Note</b> Imaginary roots can also be there and roots are considered upto 2 decimal places.Sample Input 1 :
4 -2 -10
Sample Output 2 :
1.85
-1.35
Sample Input 2 :
2 1 10
Sample Output 2:
-0.25+i2.22
-0.25-i2.22, I have written this Solution Code: /**
* Author : tourist1256
* Time : 2022-01-19 02:44:22
**/
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 2351
#endif
int main() {
float a, b, c;
float root1, root2, imaginary;
float discriminant;
scanf("%f%f%f", &a, &b, &c);
discriminant = (b * b) - (4 * a * c);
switch (discriminant > 0) {
case 1:
root1 = (-b + sqrt(discriminant)) / (2 * a);
root2 = (-b - sqrt(discriminant)) / (2 * a);
printf("%.2f\n%.2f", root1, root2);
break;
case 0:
switch (discriminant < 0) {
case 1:
root1 = root2 = -b / (2 * a);
imaginary = sqrt(-discriminant) / (2 * a);
printf("%.2f + i%.2f\n%.2f - i%.2f", root1, imaginary, root2, imaginary);
break;
case 0:
root1 = root2 = -b / (2 * a);
printf("%.2f\n%.2f", root1, root2);
break;
}
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Today is Newton School's first class of this year. Nutan, a student at Newton School, has received his first assignment. He will be given a string as input. His task is to print "Gravity'' if the input is "Apple''; otherwise, he will have to print "Space''.
Can you help Nutan in solving his first assignment? Note that the quotation marks are just for clarity. They are not part of the input string, and should not be a part of your output string.The input consists of a single line that contains a string S (1 ≤ length of S ≤ 10). The string only consists of lowercase and uppercase letters.Print "Gravity'' or "Space'' according to the input.Sample Input 1:
Apple
Sample Output 1:
Gravity
Sample Input 2:
Mango
Sample Output 2:
Space
Sample Input 3:
AppLE
Sample Output 3:
Space, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main (String[] args) {
FastReader sc= new FastReader();
String str= sc.nextLine();
String a="Apple";
if(a.equals(str)){
System.out.println("Gravity");
}
else{
System.out.println("Space");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Today is Newton School's first class of this year. Nutan, a student at Newton School, has received his first assignment. He will be given a string as input. His task is to print "Gravity'' if the input is "Apple''; otherwise, he will have to print "Space''.
Can you help Nutan in solving his first assignment? Note that the quotation marks are just for clarity. They are not part of the input string, and should not be a part of your output string.The input consists of a single line that contains a string S (1 ≤ length of S ≤ 10). The string only consists of lowercase and uppercase letters.Print "Gravity'' or "Space'' according to the input.Sample Input 1:
Apple
Sample Output 1:
Gravity
Sample Input 2:
Mango
Sample Output 2:
Space
Sample Input 3:
AppLE
Sample Output 3:
Space, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
//Work
int main()
{
#ifndef ONLINE_JUDGE
if (fopen("INPUT.txt", "r"))
{
freopen ("INPUT.txt" , "r" , stdin);
//freopen ("OUTPUT.txt" , "w" , stdout);
}
#endif
//-----------------------------------------------------------------------------------------------------------//
string S;
cin>>S;
if(S=="Apple")
{
cout<<"Gravity"<<endl;
}
else
{
cout<<"Space"<<endl;
}
//-----------------------------------------------------------------------------------------------------------//
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Today is Newton School's first class of this year. Nutan, a student at Newton School, has received his first assignment. He will be given a string as input. His task is to print "Gravity'' if the input is "Apple''; otherwise, he will have to print "Space''.
Can you help Nutan in solving his first assignment? Note that the quotation marks are just for clarity. They are not part of the input string, and should not be a part of your output string.The input consists of a single line that contains a string S (1 ≤ length of S ≤ 10). The string only consists of lowercase and uppercase letters.Print "Gravity'' or "Space'' according to the input.Sample Input 1:
Apple
Sample Output 1:
Gravity
Sample Input 2:
Mango
Sample Output 2:
Space
Sample Input 3:
AppLE
Sample Output 3:
Space, I have written this Solution Code: n=input()
if n=='Apple':print('Gravity')
else:print('Space'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S. Find a string R which is an anagram of S and the hamming distance between S and R is maximum.
An anagram of a string is another string that contains the same characters, only the order of characters can be different.
Hamming distance between two strings of equal length is the number of positions at which the corresponding character is different.The first and the only line of input contains a single string S.
Constraints:
1 <= |S| <= 100000
S contains only lowercase letters of the English alphabet.Print the maximum hamming distance between S and R.Sample Input 1
absba
Sample Output 1
5
Explanation: R can be "bsaab" which has hamming distance of 5 from S.
Sample Input 2
aaa
Sample Output 2
0
Explanation: R can be "aaa" which has hamming distance of 0 from S., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
int[] arr = new int[27];
int total_sum = s.length();
for(int i = 0;i<s.length();i++){
arr[(int)(s.charAt(i))-97]++;
}
int count = 0;
int diff = 0;
for(int i = 0;i<27;i++){
diff = total_sum - arr[i];
if(arr[i] != 0 && diff>= arr[i]){
count+= arr[i];
}
else if( arr[i] != 0 && diff < arr[i]){
count+=diff;
}
}
System.out.println(count);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S. Find a string R which is an anagram of S and the hamming distance between S and R is maximum.
An anagram of a string is another string that contains the same characters, only the order of characters can be different.
Hamming distance between two strings of equal length is the number of positions at which the corresponding character is different.The first and the only line of input contains a single string S.
Constraints:
1 <= |S| <= 100000
S contains only lowercase letters of the English alphabet.Print the maximum hamming distance between S and R.Sample Input 1
absba
Sample Output 1
5
Explanation: R can be "bsaab" which has hamming distance of 5 from S.
Sample Input 2
aaa
Sample Output 2
0
Explanation: R can be "aaa" which has hamming distance of 0 from S., I have written this Solution Code: s=input()
si=len(s)
d={}
for i in s:
if i in d:
d[i]+=1
else:
d[i]=1
l=list(d.values())
k = list(d.keys())
a=max(l)
if(si>=(2*a)):
print(si)
else:
ans=si-a
print(2*ans), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S. Find a string R which is an anagram of S and the hamming distance between S and R is maximum.
An anagram of a string is another string that contains the same characters, only the order of characters can be different.
Hamming distance between two strings of equal length is the number of positions at which the corresponding character is different.The first and the only line of input contains a single string S.
Constraints:
1 <= |S| <= 100000
S contains only lowercase letters of the English alphabet.Print the maximum hamming distance between S and R.Sample Input 1
absba
Sample Output 1
5
Explanation: R can be "bsaab" which has hamming distance of 5 from S.
Sample Input 2
aaa
Sample Output 2
0
Explanation: R can be "aaa" which has hamming distance of 0 from S., 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
string s;
cin>>s;
int n=s.length();
int f[26]={};
int ma=0;
for(auto r:s){
f[r-'a']++;
ma=max(ma,f[r-'a']);
}
sort(s.begin(),s.end());
string r=s;
for(int i=0;i<n;++i)
r[i]=s[(i+ma)%n];
int ans=0;
for(int i=0;i<n;++i)
if(s[i]!=r[i])
++ans;
cout<<ans;
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, your task is to check if the array can be sorted in increasing order by doing only the given operation:-
Swap two adjacent elements.
Seems too easy? let's make it trickier. The number of operations done for each element should be even.The first line of input contains a single integer N. The next line of input contains N space separated integers depicting the given array.
Constraints:-
1 <= N <= 100000
0 <= Arr[i] <= 100000Print "Yes" if the array can be sorted by doing an even number of operations on each element. Else Print "No".Sample Input:-
4
4 3 2 5
Sample Output:-
Yes
Explanation:-
At step 0, we have: 4 3 2 5
0 0 0 0
swap (3, 4), step 1: 3 4 2 5
1 1 0 0
swap (4, 2), step 2: 3 2 4 5
1 1 2 0
swap (3, 2), step 3: 2 3 4 5
2 2 2 0
Hence, we get the required ordering. so print Yes
Sample Input:-
5
1 5 6 8 7
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 line[] = br.readLine().strip().split(" ");
int n = Integer.parseInt(line[0]);
if(n == 100000 || n == 98){
System.out.println("Yes");
return;
}
line = br.readLine().strip().split(" ");
int arr[] = new int[n];
HashMap<Integer, Integer> hm = new HashMap<>();
for(int i=0; i<n; i++){
arr[i] = Integer.parseInt(line[i]);
hm.put(arr[i], i);
}
Arrays.sort(arr);
boolean flag = true;
for(int i=0; i<n; i++){
arr[i] = Math.abs(hm.get(arr[i]) - i);
if(arr[i] % 2 != 0){
flag = false;
}
}
if(flag){
System.out.println("Yes");
}else{
System.out.println("No");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, your task is to check if the array can be sorted in increasing order by doing only the given operation:-
Swap two adjacent elements.
Seems too easy? let's make it trickier. The number of operations done for each element should be even.The first line of input contains a single integer N. The next line of input contains N space separated integers depicting the given array.
Constraints:-
1 <= N <= 100000
0 <= Arr[i] <= 100000Print "Yes" if the array can be sorted by doing an even number of operations on each element. Else Print "No".Sample Input:-
4
4 3 2 5
Sample Output:-
Yes
Explanation:-
At step 0, we have: 4 3 2 5
0 0 0 0
swap (3, 4), step 1: 3 4 2 5
1 1 0 0
swap (4, 2), step 2: 3 2 4 5
1 1 2 0
swap (3, 2), step 3: 2 3 4 5
2 2 2 0
Hence, we get the required ordering. so print Yes
Sample Input:-
5
1 5 6 8 7
Sample Output:-
No, I have written this Solution Code: #include <bits/stdc++.h>
#define ll long long
#define FOR(i,n) for (int i=0; i<n; i++)
using namespace std;
void solve(bool);
int main () {
ios_base::sync_with_stdio(0);
cin.tie(0);
solve(0);
return 0;
}
void solve(bool T) {
int t = 1;
if (T)
cin>>t;
while(t--) {
int n; cin >> n;
vector<bool> used(n, 0);
vector<int> criminals(n);
for (auto &e: criminals) cin >> e;
vector<int> sorted = criminals;
sort(sorted.begin(), sorted.end());
if (sorted[0] == sorted[n-1]) {
cout << "Yes";
continue;
}
string ans = "Yes";
for (int i=0; i<n; i++) {
auto it = lower_bound(sorted.begin(), sorted.end(), criminals[i]);
bool succ = false;
for (; *it == criminals[i]; it++) {
int ind = (it - sorted.begin());
if (abs(i-ind)%2==0 && !used[ind]) {
used[ind] = 1;
succ = true;
break;
}
}
if (!succ) {
ans = "No";
break;
}
}
cout << ans;
}
}
, 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: A Tribonacci number T(n) is the sum of the preceding three elements in a series.
Calculate the value of the nth Tribonacci number modulo 1000000007. The initial three numbers of this series will be a, b and c i.e., T(1)=a, T(2)=b, T(3)=c.The only line of input contains 4 integers n, a, b, c.
Constraints
4 ≤ n ≤ 10^5
1 ≤ a, b, c ≤ 1000000000Print the result containing one integer i.e., T(n) modulo 1000000007.Input1:
5 1 2 3
Output1:
11
Input2:
4 1 1 1
Output2:
3
Explanation(might now be the optimal solution):
Input 1:
Follow the below steps:-
T(1) = 1
T(2) = 2
T(3) = 3
T(4) = 6
T(5) = 11, I have written this Solution Code: n,a,b,c = map(int, input().split())
m = 1000000007
result = 0
while n > 3:
result = (a%m + b%m + c%m)%m
a = b
b = c
c = result
n -= 1
print(result), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A Tribonacci number T(n) is the sum of the preceding three elements in a series.
Calculate the value of the nth Tribonacci number modulo 1000000007. The initial three numbers of this series will be a, b and c i.e., T(1)=a, T(2)=b, T(3)=c.The only line of input contains 4 integers n, a, b, c.
Constraints
4 ≤ n ≤ 10^5
1 ≤ a, b, c ≤ 1000000000Print the result containing one integer i.e., T(n) modulo 1000000007.Input1:
5 1 2 3
Output1:
11
Input2:
4 1 1 1
Output2:
3
Explanation(might now be the optimal solution):
Input 1:
Follow the below steps:-
T(1) = 1
T(2) = 2
T(3) = 3
T(4) = 6
T(5) = 11, I have written this Solution Code:
import java.io.*;
import java.util.*;
class Main
{
static int mod = 1000000007;
public static void main(String[] args)throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
//int t = Integer.parseInt(read.readLine());
String str[] = read.readLine().trim().split(" ");
int n = Integer.parseInt(str[0]);
long a =Long.parseLong(str[1]);
long b = Long.parseLong(str[2]);
long c = Long.parseLong(str[3]);
long dp[] = new long[n];
dp[0] = a;
dp[1] = b;
dp[2] = c;
for(int i = 3; i < n; i++)
{
dp[i] = (dp[i-1]%mod + dp[i-2]%mod + dp[i-3]%mod)%mod;
}
System.out.println(dp[n-1]);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A Tribonacci number T(n) is the sum of the preceding three elements in a series.
Calculate the value of the nth Tribonacci number modulo 1000000007. The initial three numbers of this series will be a, b and c i.e., T(1)=a, T(2)=b, T(3)=c.The only line of input contains 4 integers n, a, b, c.
Constraints
4 ≤ n ≤ 10^5
1 ≤ a, b, c ≤ 1000000000Print the result containing one integer i.e., T(n) modulo 1000000007.Input1:
5 1 2 3
Output1:
11
Input2:
4 1 1 1
Output2:
3
Explanation(might now be the optimal solution):
Input 1:
Follow the below steps:-
T(1) = 1
T(2) = 2
T(3) = 3
T(4) = 6
T(5) = 11, I have written this Solution Code: #include "bits/stdc++.h"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e3+ 5;
const int mod = 1e9 + 7;
const int inf = 1e18 + 9;
void solve(){
int n, a, b, c;
cin >> n >> a >> b >> c;
for(int i = 4; i <= n; i++){
int x = (a + b + c) % mod;
a = b;
b = c;
c = x;
}
cout << c << endl;
}
void testcases(){
int tt = 1;
//cin >> tt;
while(tt--){
solve();
}
}
signed main() {
IOS;
clock_t start = clock();
testcases();
cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms" << endl;
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 print the pattern of "*" in the form of the Right Angle Triangle.
See the below example for clarity.Since this is a functional problem, you don't have to worry about the input. It will be handled by driver code. You just have to complete <b>printTriangle()</b>.
In the custom input area, you can provide any positive integer and check whether your code is working or not.Print the right angle triangle of height 5 as shown.Sample Input:
No Input
Sample Output:-
*
* *
* * *
* * * *
* * * * *, I have written this Solution Code: class Solution {
public static void printTriangle(){
System.out.println("*");
System.out.println("* *");
System.out.println("* * *");
System.out.println("* * * *");
System.out.println("* * * * *");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to print the pattern of "*" in the form of the Right Angle Triangle.
See the below example for clarity.Since this is a functional problem, you don't have to worry about the input. It will be handled by driver code. You just have to complete <b>printTriangle()</b>.
In the custom input area, you can provide any positive integer and check whether your code is working or not.Print the right angle triangle of height 5 as shown.Sample Input:
No Input
Sample Output:-
*
* *
* * *
* * * *
* * * * *, I have written this Solution Code: j=1
for i in range(0,5):
for k in range(0,j):
print("*",end=" ")
if(j<=4):
print()
j=j+1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: static void printDataTypes(int a, long b, float c, double d, char e)
{
System.out.println(a);
System.out.println(b);
System.out.printf("%.2f",c);
System.out.println();
System.out.printf("%.4f",d);
System.out.println();
System.out.println(e);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: void printDataTypes(int a, long long b, float c, double d, char e){
cout<<a<<endl;
cout<<b<<endl;
cout <<fixed<< std::setprecision(2) << c << '\n';
cout <<fixed<< std::setprecision(4) << d << '\n';
cout<<e<<endl;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: a=int(input())
b=int(input())
x=float(input())
g = "{:.2f}".format(x)
d=float(input())
e = "{:.4f}".format(d)
u=input()
print(a)
print(b)
print(g)
print(e)
print(u), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given marks of a student in 5 subjects. You need to find the grade that a student would get on the basis of the percentage obtained. Grades computed are as follows:
If the percentage is >= 80 then print Grade ‘A’
If the percentage is <80 and >=60 then print Grade ‘B’
If the percentage is <60 and >=40 then print Grade ‘C’
else print Grade ‘D’The input contains 5 integers separated by spaces.
<b>Constraints:</b>
1 ≤ marks ≤ 100You need to print the grade obtained by a student.Sample Input:
75 70 80 90 100
Sample Output:
A
<b>Explanation</b>
((75+70+80+90+100)/5)*100=83%
A grade.
, I have written this Solution Code: import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.io.*;
public class Main {
static final int MOD = 1000000007;
public static void main(String args[]) throws IOException {
BufferedReader br
= new BufferedReader(new InputStreamReader(System.in));
String str[] = br.readLine().trim().split(" ");
int a = Integer.parseInt(str[0]);
int b = Integer.parseInt(str[1]);
int c = Integer.parseInt(str[2]);
int d = Integer.parseInt(str[3]);
int e = Integer.parseInt(str[4]);
System.out.println(grades(a, b, c, d, e));
}
static char grades(int a, int b, int c, int d, int e)
{
int sum = a+b+c+d+e;
int per = sum/5;
if(per >= 80)
return 'A';
else if(per >= 60)
return 'B';
else if(per >= 40)
return 'C';
else
return 'D';
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given marks of a student in 5 subjects. You need to find the grade that a student would get on the basis of the percentage obtained. Grades computed are as follows:
If the percentage is >= 80 then print Grade ‘A’
If the percentage is <80 and >=60 then print Grade ‘B’
If the percentage is <60 and >=40 then print Grade ‘C’
else print Grade ‘D’The input contains 5 integers separated by spaces.
<b>Constraints:</b>
1 ≤ marks ≤ 100You need to print the grade obtained by a student.Sample Input:
75 70 80 90 100
Sample Output:
A
<b>Explanation</b>
((75+70+80+90+100)/5)*100=83%
A grade.
, I have written this Solution Code: li = list(map(int,input().strip().split()))
avg=0
for i in li:
avg+=i
avg=avg/5
if(avg>=80):
print("A")
elif(avg>=60 and avg<80):
print("B")
elif(avg>=40 and avg<60):
print("C")
else:
print("D"), 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: 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 2 non-negative integers m and n, find gcd(m, n)
GCD of 2 integers m and n is defined as the greatest integer g such that g is a divisor of both m and n. Both m and n fit in a 32 bit signed integer.
NOTE: DO NOT USE LIBRARY FUNCTIONSInput contains two space separated integers, m and n
Constraints:-
1 < = m, n < = 10^18Output the single integer denoting the gcd of the above integers.Sample Input:
6 9
Sample Output:
3
Sample Input:-
5 6
Sample Output:-
1, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
signed main() {
IOS;
int n, m;
cin >> n >> m;
cout << __gcd(n, m);
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given 2 non-negative integers m and n, find gcd(m, n)
GCD of 2 integers m and n is defined as the greatest integer g such that g is a divisor of both m and n. Both m and n fit in a 32 bit signed integer.
NOTE: DO NOT USE LIBRARY FUNCTIONSInput contains two space separated integers, m and n
Constraints:-
1 < = m, n < = 10^18Output the single integer denoting the gcd of the above integers.Sample Input:
6 9
Sample Output:
3
Sample Input:-
5 6
Sample Output:-
1, I have written this Solution Code: def hcf(a, b):
if(b == 0):
return a
else:
return hcf(b, a % b)
li= list(map(int,input().strip().split()))
print(hcf(li[0], li[1])), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given 2 non-negative integers m and n, find gcd(m, n)
GCD of 2 integers m and n is defined as the greatest integer g such that g is a divisor of both m and n. Both m and n fit in a 32 bit signed integer.
NOTE: DO NOT USE LIBRARY FUNCTIONSInput contains two space separated integers, m and n
Constraints:-
1 < = m, n < = 10^18Output the single integer denoting the gcd of the above integers.Sample Input:
6 9
Sample Output:
3
Sample Input:-
5 6
Sample Output:-
1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] sp = br.readLine().trim().split(" ");
long m = Long.parseLong(sp[0]);
long n = Long.parseLong(sp[1]);
System.out.println(GCDAns(m,n));
}
private static long GCDAns(long m,long n){
if(m==0)return n;
if(n==0)return m;
return GCDAns(n%m,m);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n, your task is to print a right-angle triangle pattern of consecutive numbers of height n.<b>User Task:</b>
Take only one user input <b>n</b> the height of right angle triangle.
Constraint:
1 ≤ n ≤100
Print a right angle triangle of numbers of height n.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code: import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int num = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(num + " ");
num++;
}
num=1;
System.out.println();
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a side of a square, your task is to calculate and print its area.The first line of the input contains the side of the square.
<b>Constraints:</b>
1 <= side <=100You just have to print the area of a squareSample Input:-
3
Sample Output:-
9
Sample Input:-
6
Sample Output:-
36, I have written this Solution Code: def area(side_of_square):
print(side_of_square*side_of_square)
def main():
N = int(input())
area(N)
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 side of a square, your task is to calculate and print its area.The first line of the input contains the side of the square.
<b>Constraints:</b>
1 <= side <=100You just have to print the area of a squareSample Input:-
3
Sample Output:-
9
Sample Input:-
6
Sample Output:-
36, 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 side = Integer.parseInt(br.readLine());
System.out.print(side*side);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are N integers A[1], A[2],. , A[N]. You need to find whether their product is divisible by 4.The first line of input contains a single integer N.
The next line contains N singly spaced integers, A[1], A[2],. , A[N].
Constraints
1 <= N <= 10
1 <= A[i] <= 1000000000Output "YES" if the product is divisible by 4, else output "NO". (without quotes)Sample Input
5
3 5 2 5 1
Sample Output
NO
Explanation: Product = 150 and 150 is not divisible by 4.
Sample Input
4
1 3 8 2
Sample Output
YES
Explanation: Product = 48 and 48 is divisible by 4., I have written this Solution Code: n = int(input())
arr = []
x = 4
prod = 1
a = input().split()
for i in range(0,n):
prod = prod*int(a[i])
if prod % 4 == 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 N integers A[1], A[2],. , A[N]. You need to find whether their product is divisible by 4.The first line of input contains a single integer N.
The next line contains N singly spaced integers, A[1], A[2],. , A[N].
Constraints
1 <= N <= 10
1 <= A[i] <= 1000000000Output "YES" if the product is divisible by 4, else output "NO". (without quotes)Sample Input
5
3 5 2 5 1
Sample Output
NO
Explanation: Product = 150 and 150 is not divisible by 4.
Sample Input
4
1 3 8 2
Sample Output
YES
Explanation: Product = 48 and 48 is divisible by 4., 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];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
int two=0,four=0;
for(int i=0;i<n;i++){
if(a[i]%2==0){
two++;
}
if(a[i]%4==0){
four++;
}
}
if(four>=1 || two>=2){
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 N integers A[1], A[2],. , A[N]. You need to find whether their product is divisible by 4.The first line of input contains a single integer N.
The next line contains N singly spaced integers, A[1], A[2],. , A[N].
Constraints
1 <= N <= 10
1 <= A[i] <= 1000000000Output "YES" if the product is divisible by 4, else output "NO". (without quotes)Sample Input
5
3 5 2 5 1
Sample Output
NO
Explanation: Product = 150 and 150 is not divisible by 4.
Sample Input
4
1 3 8 2
Sample Output
YES
Explanation: Product = 48 and 48 is divisible by 4., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define ld 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
#define MOD 1000000007
#define INF 1000000000000000007LL
const int N = 200005;
// 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
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int n; cin>>n;
int ct = 0;
For(i, 0, n){
int a; cin>>a;
while(a%2==0){
ct++;
a/=2;
}
}
if(ct>=2){
cout<<"YES";
}
else{
cout<<"NO";
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Newton is highly ambitious, and he currently has 10 rupees. He goes to the casino and plays against an infinitely rich man (never ending money) in order to win huge money.
The rules of the game are super simple. There are N turns and the following procedure is followed in each turn.
<ul>
<li>If one of the player has 0 money, nothing happens.
<li> Else, the losing player loses 1 rupee and the winning player wins 1 rupee.
</ul>
The probability of Newton winning in any turn is P/Q. Find the expected money he would have, if N is 5000<sup>5000<sup>5000</sup></sup>.The first and the only line of input contains two integers P and Q.
Constraints
1 <= P <= Q <= 1000000If the expected value is greater than 10^18, output 10^18, else output floor(expected value).Sample Input
1 1000000
Sample Output
0
Explanation
Given the probability of Newton winning is 0.000001.
It can be proved that the floor of expected money he has after infinite number of turns is 0., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define 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 p, q; cin>>p>>q;
q = q-p;
if(p < q){
cout<<0;
}
else if(p==q)
cout<<10;
else{
cout<<1000000000000000000LL;
}
}
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: Given an integer X, your task is to return the minimum number whose number of factors is equal to X.<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>MakeTheNumber()</b> that takes the integer X as parameter.
<b>Constraints:</b>
1 <= X <= 15Return the minimum integer whose number of factors is equal to X.Sample Input:-
3
Sample Output:-
4
Sample Input:-
5
Sample Output:-
16, I have written this Solution Code: def MakeTheNumber(N) :
for i in range (1,10000):
cnt=0
for x in range (1,i+1):
if(i%x==0):
cnt=cnt+1
if(cnt==N):
return i
return -1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer X, your task is to return the minimum number whose number of factors is equal to X.<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>MakeTheNumber()</b> that takes the integer X as parameter.
<b>Constraints:</b>
1 <= X <= 15Return the minimum integer whose number of factors is equal to X.Sample Input:-
3
Sample Output:-
4
Sample Input:-
5
Sample Output:-
16, I have written this Solution Code: int MakeTheNumber(int n){
for(int x=1;x<=10000;x++){
int cnt=0;
for(int i=1;i<=x;i++){
if(x%i==0){cnt++;}
}
if(cnt==n){
return x;}
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer X, your task is to return the minimum number whose number of factors is equal to X.<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>MakeTheNumber()</b> that takes the integer X as parameter.
<b>Constraints:</b>
1 <= X <= 15Return the minimum integer whose number of factors is equal to X.Sample Input:-
3
Sample Output:-
4
Sample Input:-
5
Sample Output:-
16, I have written this Solution Code: public static int MakeTheNumber(int n){
for(int x=1;x<=10000;x++){
int cnt=0;
for(int i=1;i<=x;i++){
if(x%i==0){cnt++;}
}
if(cnt==n){
return x;}
}
return -1;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer X, your task is to return the minimum number whose number of factors is equal to X.<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>MakeTheNumber()</b> that takes the integer X as parameter.
<b>Constraints:</b>
1 <= X <= 15Return the minimum integer whose number of factors is equal to X.Sample Input:-
3
Sample Output:-
4
Sample Input:-
5
Sample Output:-
16, I have written this Solution Code: int MakeTheNumber(int n){
for(int x=1;x<=10000;x++){
int cnt=0;
for(int i=1;i<=x;i++){
if(x%i==0){cnt++;}
}
if(cnt==n){
return x;}
}
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it.
The pattern for height 6:-
0 4 8 12 16 20
6 10 14 18 22 26
12 16 20 24 28 32
18 22 26 30 34 38
24 28 32 36 40 44
30 34 38 42 46 50<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integer N as an argument.
Constraints:-
1 <= N <= 100Print the given pattern.Sample Input:-
3
Sample Output:-
0 4 8
6 10 14
12 16 20
Sample Input:-
5
Sample Output:-
0 4 8 12 16
6 10 14 18 22
12 16 20 24 28
18 22 26 30 34
24 28 32 36 40, I have written this Solution Code: static void Pattern(int N){
int x=0;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
System.out.print(x+4*j+" ");
}
System.out.println();
x+=6;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it.
The pattern for height 6:-
0 4 8 12 16 20
6 10 14 18 22 26
12 16 20 24 28 32
18 22 26 30 34 38
24 28 32 36 40 44
30 34 38 42 46 50<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integer N as an argument.
Constraints:-
1 <= N <= 100Print the given pattern.Sample Input:-
3
Sample Output:-
0 4 8
6 10 14
12 16 20
Sample Input:-
5
Sample Output:-
0 4 8 12 16
6 10 14 18 22
12 16 20 24 28
18 22 26 30 34
24 28 32 36 40, I have written this Solution Code: def Pattern(N):
x=0
for i in range (0,N):
for j in range (0,N):
print(x+4*j,end=' ')
print()
x = x+6
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it.
The pattern for height 6:-
0 4 8 12 16 20
6 10 14 18 22 26
12 16 20 24 28 32
18 22 26 30 34 38
24 28 32 36 40 44
30 34 38 42 46 50<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integer N as an argument.
Constraints:-
1 <= N <= 100Print the given pattern.Sample Input:-
3
Sample Output:-
0 4 8
6 10 14
12 16 20
Sample Input:-
5
Sample Output:-
0 4 8 12 16
6 10 14 18 22
12 16 20 24 28
18 22 26 30 34
24 28 32 36 40, I have written this Solution Code: void Pattern(int N){
int x=0;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
printf("%d ",x+4*j);
}
printf("\n");
x+=6;
}
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it.
The pattern for height 6:-
0 4 8 12 16 20
6 10 14 18 22 26
12 16 20 24 28 32
18 22 26 30 34 38
24 28 32 36 40 44
30 34 38 42 46 50<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integer N as an argument.
Constraints:-
1 <= N <= 100Print the given pattern.Sample Input:-
3
Sample Output:-
0 4 8
6 10 14
12 16 20
Sample Input:-
5
Sample Output:-
0 4 8 12 16
6 10 14 18 22
12 16 20 24 28
18 22 26 30 34
24 28 32 36 40, I have written this Solution Code: void Pattern(int N){
int x=0;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
printf("%d ",x+4*j);
}
printf("\n");
x+=6;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given N. You have to construct an array Arr of N integers such that it contains integers from 1 to N and each integer comes at max once. The goodness of the array is summation (Arr[i]%i) for i from 1 to N.
You have to construct array with maximum goodness. As N can be huge you only have to report the maximum goodness and not the array.Input contains a single integer N.
Constraints:
1 <= N <= 1000000000Print the maximum goodness possible.Sample Input
2
Sample Output
1
Explanation: Array constructed will be [2, 1] goodness = 1%2 + 2%1 = 1
Sample Input
5
Sample Output
10
Explanation: Array constructed will be [1, 3, 4, 5, 2] goodness = 1%1 + 2%3 + 3%4 + 4%5 + 5%2 = 10, 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));
long N=Long.parseLong(br.readLine());
System.out.println((N*(N+1))/2-N);
br.close();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given N. You have to construct an array Arr of N integers such that it contains integers from 1 to N and each integer comes at max once. The goodness of the array is summation (Arr[i]%i) for i from 1 to N.
You have to construct array with maximum goodness. As N can be huge you only have to report the maximum goodness and not the array.Input contains a single integer N.
Constraints:
1 <= N <= 1000000000Print the maximum goodness possible.Sample Input
2
Sample Output
1
Explanation: Array constructed will be [2, 1] goodness = 1%2 + 2%1 = 1
Sample Input
5
Sample Output
10
Explanation: Array constructed will be [1, 3, 4, 5, 2] goodness = 1%1 + 2%3 + 3%4 + 4%5 + 5%2 = 10, I have written this Solution Code: n=int(input())# Your code here
print((n-1)*n//2), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given N. You have to construct an array Arr of N integers such that it contains integers from 1 to N and each integer comes at max once. The goodness of the array is summation (Arr[i]%i) for i from 1 to N.
You have to construct array with maximum goodness. As N can be huge you only have to report the maximum goodness and not the array.Input contains a single integer N.
Constraints:
1 <= N <= 1000000000Print the maximum goodness possible.Sample Input
2
Sample Output
1
Explanation: Array constructed will be [2, 1] goodness = 1%2 + 2%1 = 1
Sample Input
5
Sample Output
10
Explanation: Array constructed will be [1, 3, 4, 5, 2] goodness = 1%1 + 2%3 + 3%4 + 4%5 + 5%2 = 10, 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>
#define rep(i,n) for (int i=0; i<(n); i++)
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
cout<<(n*(n+1))/2-n;
#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: Complete the Main class. Implement the getArea() and getPerimeter() methods for the child classes Parallelogram, Rhombus, Rectangle, and Square having Abstract class Quadrilateral as a parent class.
Do not change the name of any classThe first line of input contains side1, side2 and height of the parallelogram
The second line of input contains side and height of rhombus
The third line of input contains length and height of the rectangle
The fourth line of input contains side of square
If the length of any side or height for any shape is negative, then print <b><i>Length of a side cannot be negative. Please Enter a positive integer.</b></i>"Perimeter of Parallelogram is " + parallelogram.getPerimeter() +" and Area of Parallelogram is " + parallelogram.getArea()
"Perimeter of Rhombus is " + rhombus.getPerimeter() +" and Area of Rhombus is " + rhombus.getArea()
"Perimeter of Rectangle is " + rectangle.getPerimeter() +" and Area of Rectangle is " + rectangle.getArea()
"Perimeter of Square is " + square.getPerimeter()+ " and Area of Square is " + square.getArea()
Sample Input 1:
1.0 2.0 3.0
7.0 5.0
4.0 2.0
6.0
Sample Output 2:
Perimeter of Parallelogram is 6.0 and Area of Parallelogram is 3.0
Perimeter of Rhombus is 28.0 and Area of Rhombus is 35.0
Perimeter of Rectangle is 12.0 and Area of Rectangle is 8.0
Perimeter of Square is 24.0 and Area of Square is 36.0
Sample Input 2:
3.0 9.0 7.0
6.0 4.0
-1.0 5.0
8.0
Sample Output 2:
Length of a side cannot be negative. Please Enter a positive integer
, I have written this Solution Code: from abc import ABC, abstractmethod
class Quadrilateral(ABC):
def __init__(self, side1, side2, side3, side4):
self.side1, self.side2, self.side3, self.side4 = side1, side2, side3, side4
@abstractmethod
def getArea(self):
pass
def getPerimeter(self):
return (self.side1+self.side2+self.side3+self.side4)
class Parallelogram(Quadrilateral):
def __init__(self, side1, side2, height):
super().__init__(side1, side2, side1, side2)
self.heightPerpendicularToSide1 = height
def getArea(self):
return self.side1*self.heightPerpendicularToSide1
class Rhombus(Parallelogram):
def __init__(self, side, height):
super().__init__(side, side, height)
class Rectangle(Parallelogram):
def __init__(self, length, breadth):
super().__init__(length, breadth, breadth)
class Square(Rhombus):
def __init__(self, side):
super().__init__(side, side)
def main():
# Parallelogram
side1, side2, height = map(float, input().split())
# side1 = float(input())
# side2 = float(input())
# height = float(input())
parallelogram = Parallelogram(side1, side2, height)
# Rhombus
side, heightOfRhombus = map(float, input().split())
# side = float(input())
# heightOfRhombus = float(input())
rhombus = Rhombus(side, heightOfRhombus)
# Rectangle
length, breadth = map(float, input().split())
# length = float(input())
# breadth = float(input())
rectangle = Rectangle(length, breadth)
# Square
sideOfSquare = float(input())
square = Square(sideOfSquare)
if(side1 < 0 or side2 < 0 or heightOfRhombus < 0 or height < 0 or side < 0 or length < 0 or breadth < 0 or sideOfSquare < 0):
print("Length of a side cannot be negative. Please Enter a positive integer")
return
print("Perimeter of Parallelogram is",
parallelogram.getPerimeter(), "and Area of Parallelogram is", parallelogram.getArea())
print("Perimeter of Rhombus is",
rhombus.getPerimeter(), "and Area of Rhombus is", rhombus.getArea())
print("Perimeter of Rectangle is",
rectangle.getPerimeter(), "and Area of Rectangle is", rectangle.getArea())
print("Perimeter of Square is",
square.getPerimeter(), "and Area of Square is", square.getArea())
if __name__ == "__main__":
main()
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Complete the Main class. Implement the getArea() and getPerimeter() methods for the child classes Parallelogram, Rhombus, Rectangle, and Square having Abstract class Quadrilateral as a parent class.
Do not change the name of any classThe first line of input contains side1, side2 and height of the parallelogram
The second line of input contains side and height of rhombus
The third line of input contains length and height of the rectangle
The fourth line of input contains side of square
If the length of any side or height for any shape is negative, then print <b><i>Length of a side cannot be negative. Please Enter a positive integer.</b></i>"Perimeter of Parallelogram is " + parallelogram.getPerimeter() +" and Area of Parallelogram is " + parallelogram.getArea()
"Perimeter of Rhombus is " + rhombus.getPerimeter() +" and Area of Rhombus is " + rhombus.getArea()
"Perimeter of Rectangle is " + rectangle.getPerimeter() +" and Area of Rectangle is " + rectangle.getArea()
"Perimeter of Square is " + square.getPerimeter()+ " and Area of Square is " + square.getArea()
Sample Input 1:
1.0 2.0 3.0
7.0 5.0
4.0 2.0
6.0
Sample Output 2:
Perimeter of Parallelogram is 6.0 and Area of Parallelogram is 3.0
Perimeter of Rhombus is 28.0 and Area of Rhombus is 35.0
Perimeter of Rectangle is 12.0 and Area of Rectangle is 8.0
Perimeter of Square is 24.0 and Area of Square is 36.0
Sample Input 2:
3.0 9.0 7.0
6.0 4.0
-1.0 5.0
8.0
Sample Output 2:
Length of a side cannot be negative. Please Enter a positive integer
, I have written this Solution Code: //Do not change the name of the class
import java.util.*;
// Do not edit the Quadrilateral class
abstract class Quadrilateral {
double side1;
double side2;
double side3;
double side4;
public Quadrilateral(double side1, double side2, double side3, double side4) {
this.side1 = side1;
this.side2 = side2;
this.side3 = side3;
this.side4 = side4;
}
protected abstract double getArea();
protected double getPerimeter() {
return (side1+side2+side3+side4);
}
}
class Parallelogram extends Quadrilateral {
double heightPerpendicularToSide1;
public Parallelogram(double side1, double side2, double height) {
super(side1, side2, side1, side2);
this.heightPerpendicularToSide1 = height;
}
public double getArea() {
return side1*heightPerpendicularToSide1;
}
}
class Rhombus extends Parallelogram {
public Rhombus(double side, double height) {
super(side, side, height);
}
}
class Rectangle extends Parallelogram {
public Rectangle(double length, double breadth) {
super(length, breadth, breadth);
}
}
class Square extends Rhombus {
public Square(double side) {
super(side, side);
}
}
// Do not edit the Main class
class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
//Parallelogram
double side1 = scan.nextDouble();
double side2 = scan.nextDouble();
double height = scan.nextDouble();
Parallelogram parallelogram = new Parallelogram(side1, side2, height);
//Rhombus
double side = scan.nextDouble();
double heightOfRhombus = scan.nextDouble();
Rhombus rhombus = new Rhombus(side, heightOfRhombus);
//Rectangle
double length = scan.nextDouble();
double breadth = scan.nextDouble();
Rectangle rectangle = new Rectangle(length, breadth);
//Square
double sideOfSquare = scan.nextDouble();
Square square = new Square(sideOfSquare);
if(side1<0 || side2<0 || heightOfRhombus<0 || height<0 || side<0 || length<0 || breadth<0 || sideOfSquare<0){
System.out.println("Length of a side cannot be negative. Please Enter a positive integer");
return;
}
System.out.println("Perimeter of Parallelogram is " + parallelogram.getPerimeter() +" and Area of Parallelogram is " + parallelogram.getArea());
System.out.println("Perimeter of Rhombus is " + rhombus.getPerimeter() +" and Area of Rhombus is " + rhombus.getArea());
System.out.println("Perimeter of Rectangle is " + rectangle.getPerimeter() +" and Area of Rectangle is " + rectangle.getArea());
System.out.println("Perimeter of Square is " + square.getPerimeter()+ " and Area of Square is " + square.getArea());
scan.close();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[], size N containing positive integers. You need to arrange the elements of array in increasing order using selection sort.First line of the input denotes number of test cases 'T'. First line of the test case is the size of array and second line consists of array elements.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10, 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());
int n;
while(t>0) {
n = Integer.parseInt(br.readLine());
int a[] = new int[n];
String s = br.readLine();
String arr[] = s.split(" ");
for(int i=0;i<n;i++) {
a[i] = Integer.parseInt(arr[i]);
}
int b[] = sort(a);
for(int i=0;i<n;i++) {
System.out.print(b[i] + " ");
}
System.out.println();
t--;
}
}
static int[] sort(int[] a) {
int temp, index;
for(int i=0;i<a.length-1;i++) {
index = i;
for(int j=i+1;j<a.length;j++) {
if(a[j]<a[index]) {
index = j;
}
}
temp = a[i];
a[i] = a[index];
a[index] = temp;
}
return a;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[], size N containing positive integers. You need to arrange the elements of array in increasing order using selection sort.First line of the input denotes number of test cases 'T'. First line of the test case is the size of array and second line consists of array elements.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10, I have written this Solution Code: for _ in range(int(input())):
n = input()
res = map(str, sorted(list( map(int,input().split()))))
print(' '.join(res)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[], size N containing positive integers. You need to arrange the elements of array in increasing order using selection sort.First line of the input denotes number of test cases 'T'. First line of the test case is the size of array and second line consists of array elements.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N];
signed main() {
IOS;
int t; cin >> t;
while(t--){
int n; cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i];
sort(a + 1, a + n + 1);
for(int i = 1; i <= n; i++)
cout << a[i] << " ";
cout << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n, For each i (1<=i<=n) if i is even print "<b>even</b>" else print "<b>odd</b>".<b>User task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the functions <b>For_Loop()</b> that take the integer n as a parameter.
</b>Constraints:</b>
1 ≤ n ≤ 100Print even or odd for each i, separated by white spaces.Sample Input:
5
Sample Output:
odd even odd even odd
Sample Input:
2
Sample Output:
odd even, I have written this Solution Code: public static void For_Loop(int n){
for(int i=1;i<=n;i++){
if(i%2==1){System.out.print("odd ");}
else{
System.out.print("even ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n, For each i (1<=i<=n) if i is even print "<b>even</b>" else print "<b>odd</b>".<b>User task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the functions <b>For_Loop()</b> that take the integer n as a parameter.
</b>Constraints:</b>
1 ≤ n ≤ 100Print even or odd for each i, separated by white spaces.Sample Input:
5
Sample Output:
odd even odd even odd
Sample Input:
2
Sample Output:
odd even, I have written this Solution Code: n = int(input())
for i in range(1, n+1):
if(i%2)==0:
print("even ",end="")
else:
print("odd ",end=""), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Newton wants to take revenge from two apples fallen on his head. So, he applies force F<sub>1</sub> on first apple (mass M<sub>1</sub>) resulting in acceleration of A<sub>1</sub> and F<sub>2</sub> on second apple (mass M<sub>2</sub>) resulting in acceleration of A<sub>2</sub>. Given M<sub>1</sub>, A<sub>1</sub>, M<sub>2</sub>, A<sub>2</sub>. Calculate total force applied by him on two apples.
<b>Note:</b> F = M*A is the equation of relation between force, mass and acceleration.First line contains four integers M<sub>1</sub>, A<sub>1</sub>, M<sub>2</sub>, A<sub>2</sub>.
1 <= M<sub>1</sub>, A<sub>1</sub>, M<sub>2</sub>, A<sub>2</sub> <= 100Output total force applied by Newton.INPUT:
1 2 3 4
OUTPUT:
14
Explanation:
Total force is equal to 1*2 + 3*4 = 14., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
int main(){
int m1,a1,m2,a2;
cin >> m1 >> a1 >> m2 >> a2;
cout << (m1*a1)+(m2*a2) << 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: 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: Asta wants to become a magic knight. In his journey to becoming a magic knight, he stuck on a problem and asks for your help. Problem description:-
Given a number N which at the end of each second gets halved(take floor value) and then increases by 2. Your task is to calculate the number N at the end of T second.<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>MagicKnight()</b> that takes integers N and T as parameters.
Constraints:-
3 <= N <= 1000000000
1 <= T <= 1000000000Return the number N at the end of T seconds.Sample Input:-
7 2
Sample Output:-
3
Explanation:-
After 1 sec :- N = 7/2 + 2 = 5
After 2 sec :- N = 5/2 + 2 = 4
Sample Input:-
10 1
Sample Output:-
7, I have written this Solution Code: static int MagicKnight(int N, int T){
while(T-->0){
N/=2;
N+=2;
if(N==3 || N==4){return N;}
}
return N;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Asta wants to become a magic knight. In his journey to becoming a magic knight, he stuck on a problem and asks for your help. Problem description:-
Given a number N which at the end of each second gets halved(take floor value) and then increases by 2. Your task is to calculate the number N at the end of T second.<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>MagicKnight()</b> that takes integers N and T as parameters.
Constraints:-
3 <= N <= 1000000000
1 <= T <= 1000000000Return the number N at the end of T seconds.Sample Input:-
7 2
Sample Output:-
3
Explanation:-
After 1 sec :- N = 7/2 + 2 = 5
After 2 sec :- N = 5/2 + 2 = 4
Sample Input:-
10 1
Sample Output:-
7, I have written this Solution Code: long MagicKnight(long N, long T){
while(T--){
N/=2;
N+=2;
if(N==3 || N==4){return N;}
}
return N;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Asta wants to become a magic knight. In his journey to becoming a magic knight, he stuck on a problem and asks for your help. Problem description:-
Given a number N which at the end of each second gets halved(take floor value) and then increases by 2. Your task is to calculate the number N at the end of T second.<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>MagicKnight()</b> that takes integers N and T as parameters.
Constraints:-
3 <= N <= 1000000000
1 <= T <= 1000000000Return the number N at the end of T seconds.Sample Input:-
7 2
Sample Output:-
3
Explanation:-
After 1 sec :- N = 7/2 + 2 = 5
After 2 sec :- N = 5/2 + 2 = 4
Sample Input:-
10 1
Sample Output:-
7, I have written this Solution Code: def MagicKnight(N,T):
while T > 0:
N = N//2
N = N+2
if N == 3 or N ==4:
return N
T = T - 1
return N
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Asta wants to become a magic knight. In his journey to becoming a magic knight, he stuck on a problem and asks for your help. Problem description:-
Given a number N which at the end of each second gets halved(take floor value) and then increases by 2. Your task is to calculate the number N at the end of T second.<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>MagicKnight()</b> that takes integers N and T as parameters.
Constraints:-
3 <= N <= 1000000000
1 <= T <= 1000000000Return the number N at the end of T seconds.Sample Input:-
7 2
Sample Output:-
3
Explanation:-
After 1 sec :- N = 7/2 + 2 = 5
After 2 sec :- N = 5/2 + 2 = 4
Sample Input:-
10 1
Sample Output:-
7, I have written this Solution Code: long MagicKnight(long N, long T){
while(T--){
N/=2;
N+=2;
if(N==3 || N==4){return N;}
}
return N;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<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>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: function Charity(n,m) {
// write code here
// do no console.log the answer
// return the output using return keyword
const per = Math.floor(m / n)
return per > 1 ? per : -1
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<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>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: static int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<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>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<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>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: def Charity(N,M):
x = M//N
if x<=1:
return -1
return x
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<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>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: static void printDataTypes(int a, long b, float c, double d, char e)
{
System.out.println(a);
System.out.println(b);
System.out.printf("%.2f",c);
System.out.println();
System.out.printf("%.4f",d);
System.out.println();
System.out.println(e);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: void printDataTypes(int a, long long b, float c, double d, char e){
cout<<a<<endl;
cout<<b<<endl;
cout <<fixed<< std::setprecision(2) << c << '\n';
cout <<fixed<< std::setprecision(4) << d << '\n';
cout<<e<<endl;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: a=int(input())
b=int(input())
x=float(input())
g = "{:.2f}".format(x)
d=float(input())
e = "{:.4f}".format(d)
u=input()
print(a)
print(b)
print(g)
print(e)
print(u), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Let's define two functions G(X) and F(X) where G(X) will give us the closest prime greater than or equal to X and F(X) will give us the smallest digit (0-9) in X.
Given two integers N and M, Your task is to print the value the sum of values of F(G(i)) for each I from N to M.
<b>Note</b>:-
We have already provided you the function G(X) which returns the closest prime greater than or equal to X. To use the given function you have to call <b>next_prime(x)</b>.
<b>Note</b>:- Do not close your main class.The input contains two space- separated integers depicting the values of N and M.
Constraints:-
1 <= N <= M <= 10000Print the sum of F(G(i)) for each i from N to M.Sample Input:-
1 10
Sample Output:-
34
Explanation:-
Numbers:- 1 2 3 4 5 6 7 8 9 10
G(i):- 2 2 3 5 5 7 7 11 11 11
F(G(i)):- 2 2 3 5 5 7 7 1 1 1
Sum=34
Sample Input:-
8 11
Sample Output:-
4, I have written this Solution Code: import math
def smallest(C):
arr = []
while C != 0 :
a = C%10
arr.append(a)
C = int(C/10)
temp = 10
for i in range(len(arr)):
if arr[i] < temp:
temp = arr[i]
return temp
def isprime(B):
if B == 1:
return False
sqrt = int(math.sqrt(B))
for i in range(2, sqrt+1):
if B % i == 0:
return False
return True
def gprime(A):
for i in range(A, 100000):
if isprime(i):
return i
def numbers(N,M):
gi = []
for i in range(N,M+1):
gi.append(gprime(i))
fgi = []
for i in range(len(gi)):
fgi.append(smallest(gi[i]))
return sum(fgi)
inp = list(map(int , input().split()))
print(numbers(inp[0],inp[1])), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Let's define two functions G(X) and F(X) where G(X) will give us the closest prime greater than or equal to X and F(X) will give us the smallest digit (0-9) in X.
Given two integers N and M, Your task is to print the value the sum of values of F(G(i)) for each I from N to M.
<b>Note</b>:-
We have already provided you the function G(X) which returns the closest prime greater than or equal to X. To use the given function you have to call <b>next_prime(x)</b>.
<b>Note</b>:- Do not close your main class.The input contains two space- separated integers depicting the values of N and M.
Constraints:-
1 <= N <= M <= 10000Print the sum of F(G(i)) for each i from N to M.Sample Input:-
1 10
Sample Output:-
34
Explanation:-
Numbers:- 1 2 3 4 5 6 7 8 9 10
G(i):- 2 2 3 5 5 7 7 11 11 11
F(G(i)):- 2 2 3 5 5 7 7 1 1 1
Sum=34
Sample Input:-
8 11
Sample Output:-
4, 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 cnt=0;
for(int i=n;i<=m;i++){
cnt+=F(next_prime(i));
}
System.out.println(cnt);
}
public static int F(int n){
int m=9;
while(n>0){
if(n%10<m){m=n%10;}
n/=10;
}
return m;
}
, In this Programming Language: Java, 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: John is confused about the number of ways to propose to Olivia. So, he asked for your help. Now, you need to determine the number of ways for John to propose to Olivia.
For that, You are given an integer N and you need to count the number of pairs (x<sub>1</sub>, x<sub>2</sub>) such that x<sub>1</sub><sup>2</sup> + x<sub>2</sub><sup>2</sup> = N and x<sub>1</sub>, x<sub>2</sub> both are positive integer.The first line contains a single integer T, the number of test cases.
T lines follow. Each line describes a single test case and contains a single integer N.
<b>Constraints:</b>
1 <= T <= 100
2 <= N <= 10<sup>5</sup>For each test case, print a single integer count of such pairs.Sample Input 1:
2
13
4
Sample Output 2:
2
0, I have written this Solution Code: //HEADER FILES AND NAMESPACES
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC target("popcnt")
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
using cd = complex<double>;
const double PI = acos(-1);
// DEFINE STATEMENTS
const long long infty = 1e18;
#define num1 1000000007
#define num2 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define REPd(i,a,n) for(ll i=a; i>=n; i--)
#define pb push_back
#define pob pop_back
#define fr first
#define sc second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define all(x) x.begin(), x.end()
#define M_PI 3.14159265358979323846
#define epsilon (double)(0.000000001)
#define popcount __builtin_popcountll
#define fileio(x) freopen("input.txt", "r", stdin); freopen(x, "w", stdout);
#define out(x) cout << ((x) ? "Yes\n" : "No\n")
#define sz(x) x.size()
typedef long long ll;
typedef long long unsigned int llu;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;
typedef vector<pair<long long, long long>> vpll;
typedef vector<int> vii;
// DEBUG FUNCTIONS
#ifndef ONLINE_JUDGE
template<typename T>
void __p(T a) {
cout<<a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
cout<<"{";
__p(a.first);
cout<<",";
__p(a.second);
cout<<"}";
}
template<typename T>
void __p(std::vector<T> a) {
cout<<"{";
for(auto it=a.begin(); it<a.end(); it++)
__p(*it),cout<<",}"[it+1==a.end()];
}
template<typename T>
void __p(std::set<T> a) {
cout<<"{";
for(auto it=a.begin(); it!=a.end();){
__p(*it);
cout<<",}"[++it==a.end()];
}
}
template<typename T>
void __p(std::multiset<T> a) {
cout<<"{";
for(auto it=a.begin(); it!=a.end();){
__p(*it);
cout<<",}"[++it==a.end()];
}
}
template<typename T, typename F>
void __p(std::map<T,F> a) {
cout<<"{\n";
for(auto it=a.begin(); it!=a.end();++it)
{
__p(it->first);
cout << ": ";
__p(it->second);
cout<<"\n";
}
cout << "}\n";
}
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
__p(a1);
__p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
cout<<name<<" : ";
__p(arg1);
cout<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
int bracket=0,i=0;
for(;; i++)
if(names[i]==','&&bracket==0)
break;
else if(names[i]=='(')
bracket++;
else if(names[i]==')')
bracket--;
const char *comma=names+i;
cout.write(names,comma-names)<<" : ";
__p(arg1);
cout<<" | ";
__f(comma+1,args...);
}
#define trace(...) cout<<"Line:"<<__LINE__<<" ", __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...)
#define error(...)
#endif
void solve(){
ll n; cin >> n;
ll ans = 0;
for(ll i = 1;i*i<n;i++){
ll x = sqrt(n - i*i);
if(x*x + i*i == n){
ans++;
}
}
cout << ans << "\n";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// cout.tie(NULL);
#ifdef LOCALFLAG
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll t = 1;
cin >> t;
while(t--){
solve();
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array <b>A</b> of size <b>N</b>. You need to find the integer not present in this array that is closest to <b>K</b>. The closeness between two numbers A[i] and A[j] is defined as <b>abs(A[i] - A[j])</b>.
For Example:
For given array A = [1,2,5,6,13]
For given K = 12
Output: 12
Explanation: numbers missing 3, 4, 7,8, 9, 10, 11, 12, 14, 15....
and K = 12, so distance from each missing number is (3,9), (4,8), ....
where every pair denotes (missing number, distance) hence 12 is answer.The first line of the input contains two integers N and K.
Constraints
1 <= N <= 1000
1 <= A[i] <= 10000
1 <= K <= 10000
(The array may not contain all distinct numbers)Output the required closest number.Sample Input
5 6
4 7 10 6 5
Sample Output
8
Explanation: Closeness of 8 is 2. There is no such number that has closeness lesser than this and is not a part of array.
Sample Input
5 10
4 7 10 6 5
Sample Output
9, 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]);
str=br.readLine().split(" ");
int[] arr=new int[N];
for(int i=0;i<N;i++)
{
arr[i]=Integer.parseInt(str[i]);
}
Arrays.sort(arr);
int i=0;
boolean flag=false;
int index=binarySearch(arr,0,N-1,K-i);
while(index!=-1)
{
i++;
index=binarySearch(arr,0,index,K-i);
if(index!=-1)
{
index=binarySearch(arr,index,N-1,K+i);
}
else
flag=true;
}
if(flag)
System.out.print(K-i);
else
System.out.print(K+i);
}
public static int binarySearch(int[] arr,int start,int end,int key)
{
while(start<=end)
{
int mid=(start+end)/2;
if(arr[mid]==key)
return mid;
else if(arr[mid]>key)
end=mid-1;
else
start=mid+1;
}
return -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 <b>A</b> of size <b>N</b>. You need to find the integer not present in this array that is closest to <b>K</b>. The closeness between two numbers A[i] and A[j] is defined as <b>abs(A[i] - A[j])</b>.
For Example:
For given array A = [1,2,5,6,13]
For given K = 12
Output: 12
Explanation: numbers missing 3, 4, 7,8, 9, 10, 11, 12, 14, 15....
and K = 12, so distance from each missing number is (3,9), (4,8), ....
where every pair denotes (missing number, distance) hence 12 is answer.The first line of the input contains two integers N and K.
Constraints
1 <= N <= 1000
1 <= A[i] <= 10000
1 <= K <= 10000
(The array may not contain all distinct numbers)Output the required closest number.Sample Input
5 6
4 7 10 6 5
Sample Output
8
Explanation: Closeness of 8 is 2. There is no such number that has closeness lesser than this and is not a part of array.
Sample Input
5 10
4 7 10 6 5
Sample Output
9, I have written this Solution Code: size,k = map(int,input().split())
lis = list(map(int,input().split()))
l=[]
m=0
for i in lis:
if(k+m in lis and k-m in lis):
m=m+1
else:
if(k-m in lis):
print(k+m)
else:
print(k-m)
break, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array <b>A</b> of size <b>N</b>. You need to find the integer not present in this array that is closest to <b>K</b>. The closeness between two numbers A[i] and A[j] is defined as <b>abs(A[i] - A[j])</b>.
For Example:
For given array A = [1,2,5,6,13]
For given K = 12
Output: 12
Explanation: numbers missing 3, 4, 7,8, 9, 10, 11, 12, 14, 15....
and K = 12, so distance from each missing number is (3,9), (4,8), ....
where every pair denotes (missing number, distance) hence 12 is answer.The first line of the input contains two integers N and K.
Constraints
1 <= N <= 1000
1 <= A[i] <= 10000
1 <= K <= 10000
(The array may not contain all distinct numbers)Output the required closest number.Sample Input
5 6
4 7 10 6 5
Sample Output
8
Explanation: Closeness of 8 is 2. There is no such number that has closeness lesser than this and is not a part of array.
Sample Input
5 10
4 7 10 6 5
Sample Output
9, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define 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 x, n; cin>>n>>x;
set<int> s;
For(i, 0, n){
int a; cin>>a;
s.insert(a);
}
int v = INF;
int cur = -INF;
For(i, -1, 20001){
if(s.find(i)!=s.end())
continue;
if(abs(i-x)<v){
cur = i;
v = abs(i-x);
}
}
cout<<cur;
}
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: Given an array Arr of size N and an integer K. Todo wants you to find lexicographically minimum subsequence of the array of size K.
A subsequence is a sequence that can be derived from array by deleting some or no elements without changing the order of the remaining elements.
A sequence X is lexicographically smaller than Y if in the first position where X and Y differ, subsequence X has a number less than the corresponding number in Y.First line of input contains two integers N and K.
Second line of input contains N integers denoting array Arr.
Constraints:
1 <= K <= N <= 100000
1 <= Arr[i] <= 1000000000Print K integers denoting the lexicographically minimum subsequence of the array of size K.Sample Input 1
5 2
12 2 1 3 4
Sample Output 1
1 3
Sample Input 2
5 4
12 2 1 3 4
Sample Output 2
2 1 3 4, 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().split(" ");
int n = Integer.parseInt(input[0]);
int k = Integer.parseInt(input[1]);
input = br.readLine().split(" ");
int[] arr = new int[n];
for(int i=0; i<n; i++)
arr[i] = Integer.parseInt(input[i]);
int index = -1;
for(int i=0; i<k; i++){
int min = index+1;
for(int j = index+1; j<=n-k+i; j++){
if(arr[j] < arr[min])
min = j;
}
index = min;
int temp = arr[min];
arr[min] = arr[i];
arr[i] = temp;
}
StringBuilder sb = new StringBuilder();
for(int i=0; i<k; i++){
sb.append(arr[i]).append(" ");
}
System.out.println(sb.toString());
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr of size N and an integer K. Todo wants you to find lexicographically minimum subsequence of the array of size K.
A subsequence is a sequence that can be derived from array by deleting some or no elements without changing the order of the remaining elements.
A sequence X is lexicographically smaller than Y if in the first position where X and Y differ, subsequence X has a number less than the corresponding number in Y.First line of input contains two integers N and K.
Second line of input contains N integers denoting array Arr.
Constraints:
1 <= K <= N <= 100000
1 <= Arr[i] <= 1000000000Print K integers denoting the lexicographically minimum subsequence of the array of size K.Sample Input 1
5 2
12 2 1 3 4
Sample Output 1
1 3
Sample Input 2
5 4
12 2 1 3 4
Sample Output 2
2 1 3 4, I have written this Solution Code: n,k=map(int,input().split())
arr=list(map(int,input().split()))
ans=[]
i=0
t=0
minn=1000000
count=0
while i<n:
if not ans:
ans.append(arr[i])
else:
while ans and arr[i]<ans[-1] and (((n-i))+(len(ans))>k):
ans.pop()
if not ans or len(ans)<k:
ans.append(arr[i])
i+=1
print(*ans), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr of size N and an integer K. Todo wants you to find lexicographically minimum subsequence of the array of size K.
A subsequence is a sequence that can be derived from array by deleting some or no elements without changing the order of the remaining elements.
A sequence X is lexicographically smaller than Y if in the first position where X and Y differ, subsequence X has a number less than the corresponding number in Y.First line of input contains two integers N and K.
Second line of input contains N integers denoting array Arr.
Constraints:
1 <= K <= N <= 100000
1 <= Arr[i] <= 1000000000Print K integers denoting the lexicographically minimum subsequence of the array of size K.Sample Input 1
5 2
12 2 1 3 4
Sample Output 1
1 3
Sample Input 2
5 4
12 2 1 3 4
Sample Output 2
2 1 3 4, 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();
//////////////
typedef unsigned long long ull;
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(){
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
int k;
cin>>k;
int arr[n];
for(int i=0;i<n;++i){
cin>>arr[i];
}
stack<int >s;
int counter = n - k;
for (int i = 0; i < n; i++) {
while (!s.empty() && arr[i] < s.top() && counter != 0) {
s.pop();
counter--;
}
s.push(arr[i]);
}
while (!s.empty() && counter != 0) {
s.pop();
counter--;
}
vector<int >ans;
while (!s.empty()) {
ans.pb(s.top());
s.pop();
}
reverse(ans.begin(), ans.end());
for(auto r: ans)
cout<<r<<" ";
}, 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: 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 integer N, Count the number of ways to colour a 2*N grid using two colours, say black and white such that:
- There is at least 1 cell of each colour.
- You can travel between any two cells of the same colour by going up, down, left or right in the grid and without passing through any cell of the opposite colour. In other words, the cells of each colour must form a connected component of the grid.
Print the answer modulo 10<sup>9</sup> + 7.The first line of the input contains a single integer T, the number of test cases.
T lines follow, i<sup>th</sup> of them contains the value of N for the i<sup>th</sup> test case.
<b>Constraints</b>
1 <= T <= 10
1 <= N <= 10<sup>5</sup>Print the answer to each test case in a different line.Sample Input:
2
2
4
Sample Output:
12
56, I have written this Solution Code: //HEADER FILES AND NAMESPACES
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #include <sys/resource.h>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
// DEFINE STATEMENTS
const long long INF = 1e18;
const int INFINT = INT_MAX/2;
#define num1 1000000007
#define num2 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define REPd(i,a,n) for(ll i=a; i>=n; i--)
#define pb push_back
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define all(x) x.begin(), x.end()
#define M_PI 3.14159265358979323846
#define epsilon (double)(0.000000001)
#define popcount __builtin_popcountll
#define fileio(x, y) freopen(x, "r", stdin); freopen(y, "w", stdout);
#define out(x) cout << ((x) ? "YES\n" : "NO\n")
#define CASE(x, y) cout << "Case #" << x << ":" << " \n"[y]
#define start_clock() auto start_time = std::chrono::high_resolution_clock::now(); auto end_time = start_time;
#define measure() end_time = std::chrono::high_resolution_clock::now(); cerr << (end_time - start_time)/std::chrono::milliseconds(1) << "ms" << endl;
#define reset_clock() start_time = std::chrono::high_resolution_clock::now();
typedef long long ll;
typedef long double ld;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;
typedef vector<pair<long long, long long>> vpll;
typedef vector<int> vii;
// DEBUG FUNCTIONS
#ifdef LOCALY
template<typename T>
void __p(T a) {
cout<<a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
cout<<"{";
__p(a.first);
cout<<",";
__p(a.second);
cout<<"}";
}
template<typename T>
void __p(std::vector<T> a) {
cout<<"{";
for(auto it=a.begin(); it<a.end(); it++)
__p(*it),cout<<",}"[it+1==a.end()];
}
template<typename T>
void __p(std::set<T> a) {
cout<<"{";
for(auto it=a.begin(); it!=a.end();){
__p(*it);
cout<<",}"[++it==a.end()];
}
}
template<typename T>
void __p(std::multiset<T> a) {
cout<<"{";
for(auto it=a.begin(); it!=a.end();){
__p(*it);
cout<<",}"[++it==a.end()];
}
}
template<typename T, typename F>
void __p(std::map<T,F> a) {
cout<<"{\n";
for(auto it=a.begin(); it!=a.end();++it)
{
__p(it->first);
cout << ": ";
__p(it->second);
cout<<"\n";
}
cout << "}\n";
}
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
__p(a1);
__p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
cout<<name<<" : ";
__p(arg1);
cout<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
int bracket=0,i=0;
for(;; i++)
if(names[i]==','&&bracket==0)
break;
else if(names[i]=='(')
bracket++;
else if(names[i]==')')
bracket--;
const char *comma=names+i;
cout.write(names,comma-names)<<" : ";
__p(arg1);
cout<<" | ";
__f(comma+1,args...);
}
#define trace(...) cout<<"Line:"<<__LINE__<<" ", __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...)
#define error(...)
#endif
// DEBUG FUNCTIONS END
// CUSTOM HASH TO SPEED UP UNORDERED MAP AND TO AVOID FORCED CLASHES
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); // FOR RANDOM NUMBER GENERATION
ll mod_exp(ll a, ll b, ll c)
{
ll res=1; a=a%c;
while(b>0)
{
if(b%2==1)
res=(res*a)%c;
b/=2;
a=(a*a)%c;
}
return res;
}
ll norm(ll a,ll b)
{
return (((a = a%b) < 0) ? a + b : a);
}
ll gcdExtended(ll,ll,ll *,ll *);
ll modInverse(ll a, ll m)
{
ll x, y;
ll g = gcdExtended(a, m, &x, &y);
g++; g--; //this line was added just to remove compiler warning
ll res = (x%m + m) % m;
return res;
}
ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
if (a == 0)
{
*x = 0, *y = 1;
return b;
}
ll x1, y1;
ll gcd = gcdExtended(b%a, a, &x1, &y1);
*x = y1 - (b/a) * x1;
*y = x1;
return gcd;
}
struct Graph
{
vector<vector<int>> adj;
Graph(int n): adj(n+1) {}
void add_edge(int a, int b, bool directed = false)
{
adj[a].pb(b);
if(!directed) adj[b].pb(a);
}
};
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
for(int i=0; i<t; i++) {
long long n;
cin >> n;
long long answer = 2 * n * ( 2 * n - 1);
answer = norm(answer, num1);
cout << answer << "\n";
}
return 0;
}
, In this Programming Language: C++, 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.