Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
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: 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: Given an array <b>A</b> of N integers, For each i (1 β€ i β€ N) your task is to find the value of x+y,
where x is the largest number less than i such that A[x]>A[i] and (A[x] is the element present at position x.)
y is the smallest number greater than i such that A[y]>A[i]
If there is no x < i such that A[x] > A[i], then take x=β1. Similarly, if there is no y>i such that A[y]>A[i], then take y=β1.First line consists of a single integer denoting N.
Second line consists of N space separated integers denoting the array A.
Constraints:
1 β€ N β€ 1000000
1 β€ A[i] β€ 10000000000Print N space separated integers, denoting x+y for each i(1 β€ i β€ N)Sample Input
5
5 4 1 3 2
Sample Output
-2 0 6 1 3
Explanation:-
For element 5:- x=-1(No element exist greater than 5 in left), y=-1 (No element exist greater than 5 in right)
For element 4:- x=1, y=-1
For element 1:- x=2, y=4
For element 3:- x=2, y=-1
For element 2:- x=4, y=-1
Sample Input
5
6 4 6 8 2
Sample Output
3 4 3 -2 3, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static int maxleft(int a[],int pos)
{
if(pos==1)
{
return -1;
}
else
{int max=a[pos];int s=-1;
for(int i=pos-1;i>=0;i--)
{
if(max<a[i])
{
s=i;
break;
}
}
if(s==pos)
{
return -1;
}
else
{
return s;
}
}
}
static int maxright(int a[],int pos,int n)
{
int max=a[pos];
int s=-1;
if(pos==n)
{
return -1;
}
else
{ for(int i=pos+1;i<=n;i++)
{
if(max<a[i])
{
s=i;
break;
}
}
if(s==pos)
{
return -1;
}
else
{
return s;
}
}
}
public static void main (String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
int a[]=new int[n+1];
StringTokenizer st=new StringTokenizer(br.readLine()," ");
for(int i=1;i<n+1;i++)
{
a[i]=Integer.parseInt(st.nextToken());
}
for(int i=1;i<n+1;i++)
{
int maxl=maxleft(a,i);
int maxr=maxright(a,i,n);
System.out.print((maxl+maxr)+" ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array <b>A</b> of N integers, For each i (1 β€ i β€ N) your task is to find the value of x+y,
where x is the largest number less than i such that A[x]>A[i] and (A[x] is the element present at position x.)
y is the smallest number greater than i such that A[y]>A[i]
If there is no x < i such that A[x] > A[i], then take x=β1. Similarly, if there is no y>i such that A[y]>A[i], then take y=β1.First line consists of a single integer denoting N.
Second line consists of N space separated integers denoting the array A.
Constraints:
1 β€ N β€ 1000000
1 β€ A[i] β€ 10000000000Print N space separated integers, denoting x+y for each i(1 β€ i β€ N)Sample Input
5
5 4 1 3 2
Sample Output
-2 0 6 1 3
Explanation:-
For element 5:- x=-1(No element exist greater than 5 in left), y=-1 (No element exist greater than 5 in right)
For element 4:- x=1, y=-1
For element 1:- x=2, y=4
For element 3:- x=2, y=-1
For element 2:- x=4, y=-1
Sample Input
5
6 4 6 8 2
Sample Output
3 4 3 -2 3, I have written this Solution Code: n=int(input())
arr=list(map(int,input().split()))
stk=[[arr[0],0]]
x=[-1]
for i in range(1,len(arr)):
if stk[-1][0]>arr[i]:
x.append(stk[-1][1]+1)
stk.append([arr[i],i])
else:
while stk and stk[-1][0]<=arr[i]:
stk.pop()
if not stk:
x.append(-1)
stk.append([arr[i],i])
else:
x.append(stk[-1][1]+1)
stk.append([arr[i],i])
stk.clear()
stk=[[arr[-1],len(arr)-1]]
y=[-1]
for i in reversed(range(len(arr)-1)):
if stk[-1][0]>arr[i]:
y.append(stk[-1][1]+1)
stk.append([arr[i],i])
else:
while stk and stk[-1][0]<=arr[i]:
stk.pop()
if not stk:
y.append(-1)
stk.append([arr[i],i])
else:
y.append(stk[-1][1]+1)
stk.append([arr[i],i])
i=0
j=len(y)-1
while i<len(x) and j>=0:
print(x[i]+y[j],end=' ')
i+=1
j-=1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array <b>A</b> of N integers, For each i (1 β€ i β€ N) your task is to find the value of x+y,
where x is the largest number less than i such that A[x]>A[i] and (A[x] is the element present at position x.)
y is the smallest number greater than i such that A[y]>A[i]
If there is no x < i such that A[x] > A[i], then take x=β1. Similarly, if there is no y>i such that A[y]>A[i], then take y=β1.First line consists of a single integer denoting N.
Second line consists of N space separated integers denoting the array A.
Constraints:
1 β€ N β€ 1000000
1 β€ A[i] β€ 10000000000Print N space separated integers, denoting x+y for each i(1 β€ i β€ N)Sample Input
5
5 4 1 3 2
Sample Output
-2 0 6 1 3
Explanation:-
For element 5:- x=-1(No element exist greater than 5 in left), y=-1 (No element exist greater than 5 in right)
For element 4:- x=1, y=-1
For element 1:- x=2, y=4
For element 3:- x=2, y=-1
For element 2:- x=4, y=-1
Sample Input
5
6 4 6 8 2
Sample Output
3 4 3 -2 3, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
stack <pair<long long,int >> s,s1;
pair<long long,int> p;
long long b[n];
long long a[n];
for(int i=0;i<n;i++){
cin>>a[i];
while(!(s.empty())){
if(s.top().first>a[i]){break;}
s.pop();
}
if(s.empty()){b[i]=-1;}
else{b[i]=s.top().second+1;}
p.first=a[i];
p.second=i;
s.push(p);
}
for(int i=n-1;i>=0;i--){
while(!(s1.empty())){
if(s1.top().first>a[i]){break;}
s1.pop();
}
if(s1.empty()){b[i]+=-1;}
else{b[i]+=s1.top().second+1;}
p.first=a[i];
p.second=i;
s1.push(p);
}
for(int i=0;i<n;i++){
cout<<b[i]<<" ";
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string, convert it to a list containing all of its elements only once without any repetition, even if there is repetition in the string.
hint - you might use sets for this.The input would be a string containing 5 characters. Each character can be any alpha numeric value.The output would be a sorted list with no repeating elementsSample input
abbbc
Sample output
['a', 'b', 'c']
Explanation-
the string 'abbbc' contains elements 'a','b', and 'c' , therefore they are printed out in the list without any duplication., I have written this Solution Code: my_list = []
strin = input()
for i in range(5):
my_list.append(strin[i])
print(sorted(list(set(my_list)))), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of N integers. You have to find whether A has some subsequence of length at least 3 that is a palindrome.First line of the input contains an integer N.
The second line of the input contains N space seperated integers.
Constraints:
1 <= N <= 5000
1 <= A<sub>i</sub> <= 10<sup>9</sup>Print "YES" if A has some subseqeuence of length at least 3 that is a palindrome, else print "NO", without the quotes.Sample Input:
5
1 5 2 2 1
Sample Output:
YES
Explanation:
We pick the elements at indices 1, 3, 4, 5 (1- indexed) making the subsequence: [1, 2, 2, 1], which is a palindrome., I have written this Solution Code: def sunpal(n,a):
ok=False
for i in range(n):
for j in range(i+2,n):
if a[i]==a[j]:
ok=True
return("YES" if ok else "NO")
if __name__=="__main__":
n=int(input())
a=input().split()
res=sunpal(n,a)
print(res), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of N integers. You have to find whether A has some subsequence of length at least 3 that is a palindrome.First line of the input contains an integer N.
The second line of the input contains N space seperated integers.
Constraints:
1 <= N <= 5000
1 <= A<sub>i</sub> <= 10<sup>9</sup>Print "YES" if A has some subseqeuence of length at least 3 that is a palindrome, else print "NO", without the quotes.Sample Input:
5
1 5 2 2 1
Sample Output:
YES
Explanation:
We pick the elements at indices 1, 3, 4, 5 (1- indexed) making the subsequence: [1, 2, 2, 1], which is a palindrome., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int long long
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using T = pair<int, int>;
typedef long double ld;
const int mod = 1e9 + 7;
const int INF = 1e18;
void solve(){
int N;
cin >> N;
map<int, int> mp;
string ans = "NO";
for(int i = 1; i <= N; i++) {
int a;
cin >> a;
if(mp[a] != 0 and mp[a] <= i - 2) {
ans = "YES";
}
if(mp[a] == 0) mp[a] = i;
}
cout << ans;
}
signed main(){
fast
int t = 1;
// cin >> t;
for(int i = 1; i <= t; i++){
solve();
if(i != t) cout << endl;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given A, B, and C as the sides of a triangle, find whether the triangle is scalene. It is guaranteed that the sides represent a valid triangle.
Note: A triangle is said to be scalene if all three sides of the triangle are distinct.The first line of input consists of three space- separated integers A, B, and C β the length of the three sides of the triangle.
<b>Constraints :</b>
1 ≤ A ≤ B ≤ C ≤ 10Output on a new line, YES, if the triangle is scalene, and NO otherwise.Sample Input:-
2 3 4
Sample Output:-
YES
Sample Input:-
1 2 2
Sample Output:-
NO, I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
class Solution {
public void Solve(int a,int b,int c) {
if(a!=b && b!=c)
System.out.println("YES");
else
System.out.println("NO");
}
}
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
//StringBuilder sss = new StringBuilder("");
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
assert(n >= 1 && n <= 10);
int m=sc.nextInt();
assert(m >= 1 && m <= 10);
int o=sc.nextInt();
assert(o >= 1 && o <= 10);
Solution obj=new Solution();
obj.Solve(n,m,o);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a tree with N nodes, where the edges have weights. The weights of the edges are hidden. Your objective is to find the weights of all the edges. To help you find the weights, for M pairs of nodes, you are given the xor of the weight of the edges on the shortest path connecting those nodes.
Formally, you are given a tree with weighted edges, but whose weights are unknown. The value of a path between two nodes A and B is defined as:
value(A,B) = XOR of the weight of the edges on the shortest path from A to B.
You are given the values of M paths. You have to determine how many different possible assignments of weights will satisfy the given information.
If no assignment satisfying the given constraints exist then print "Zero". If more than one assignment satisfies the given constraints then print "Multiple". If only a unique solution exists, print "One" on the first line and print the XOR of the square of the edge weights on the next line.The first line of the input contains two space-separated integers N and M β the number of vertices in the tree and the number of paths whose values are given.
Then N-1 lines follow, the i<sup>th</sup> line contains two space-separated integers X<sub>i</sub> and Y<sub>i</sub> representing an edge between them.
Then M lines follow, the i<sup>th</sup> line contains three space-separated integers A<sub>i</sub>, B<sub>i</sub> and C<sub>i</sub> β the value of the path from A<sub>i</sub> to B<sub>i</sub> being C<sub>i</sub>.
<b> Constraints: </b>
2 β€ N β€ 10<sup>5</sup>
1 β€ M β€ 2Γ10<sup>5</sup>
1 β€ X<sub>i</sub>, Y<sub>i</sub> β€ N, (X<sub>i</sub> ≠ Y<sub>i</sub>)
1 β€ A<sub>i</sub>, B<sub>i</sub> β€ N, (A<sub>i</sub> ≠ B<sub>i</sub>)
0 β€ C<sub>i</sub> < 2<sup>16</sup>If no assignment satisfying the given constraints exist, print "Zero".
If more than one assignment satisfies the given constraints, print "Multiple".
If only a unique solution exists, print "One" on the first line and print the XOR of the square of the edge weights on the next line.Sample Input 1:
2 1
1 2
2 1 3
Sample Output 1:
One
9
Sample Explanation 1:
Only a single weight can be assigned to the given edge with weight equal to 3.
The square of the edge weight is 9, as there is only a single edge so the value of the XOR of squares is also equal to 9.
Sample Input 2:
4 3
1 2
2 4
1 3
1 4 3
2 4 2
2 3 5
Sample Output 2:
One
21
Sample Explanation 2:
The only possible assignment of weights is:
weight of (1, 2) = 1, weight of (2, 4) = 2, weight of (1, 3) = 4
Thus, the XOR of their squares is (1^4^16) = 21.
Sample Input 3:
3 1
1 2
2 3
1 3 5
Sample Output 3:
Multiple
Sample Explanation 3:
There can be multiple solutions satisfying the given input.
One possible solution is (1, 2) = 0 and (2, 3) = 5 and another possible solution is (1, 2) = 1 and (2, 3) = 4.
, I have written this Solution Code: #include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<iostream>
#define lowbit(x) ((x)&(-x))
#define Finline __inline__ __attribute__ ((always_inline))
#define DEBUG printf("Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f,Inf=0x7fffffff;
const ll INF=0x7fffffffffffffff;
const double eps=1e-10;
uint seed=19260817;
const uint _RAND_MAX_=4294967295u;
Finline uint Rand(){return seed=seed*998244353u+1000000007u;}
template <typename _Tp>_Tp gcd(const _Tp &a,const _Tp &b){return (!b)?a:gcd(b,a%b);}
template <typename _Tp>Finline _Tp abs(const _Tp &a){return a>0?a:-a;}
template <typename _Tp>Finline _Tp max(const _Tp &a,const _Tp &b){return a<b?b:a;}
template <typename _Tp>Finline _Tp min(const _Tp &a,const _Tp &b){return a<b?a:b;}
template <typename _Tp>Finline void chmax(_Tp &a,const _Tp &b){(a<b)&&(a=b);}
template <typename _Tp>Finline void chmin(_Tp &a,const _Tp &b){(a>b)&&(a=b);}
template <typename _Tp>Finline bool _cmp(const _Tp &a,const _Tp &b){return abs(a-b)<=eps;}
template <typename _Tp>Finline void read(_Tp& x)
{
register char ch(getchar());
bool f(false);
while(ch<48||ch>57) f|=ch==45,ch=getchar();
x=ch&15,ch=getchar();
while(ch>=48&&ch<=57) x=(((x<<2)+x)<<1)+(ch&15),ch=getchar();
if(f) x=-x;
}
template <typename _Tp,typename... Args>Finline void read(_Tp &t,Args &...args)
{
read(t);read(args...);
}
Finline int read_str(char *s)
{
register char ch(getchar());
while(ch==' '||ch=='\r'||ch=='\n') ch=getchar();
register char *tar=s;
*tar=ch,ch=getchar();
while(ch!=' '&&ch!='\r'&&ch!='\n'&&ch!=EOF) *(++tar)=ch,ch=getchar();
return tar-s+1;
}
const int N=100005;
Finline int id(const int &x,const int &y,const int &z)
{
return 32*(x-1)+z*16+y+1;
}
struct edge{
int v,nxt;
}c[N<<1];
int front[N],cnt;
Finline void add(const int &u,const int &v)
{
c[++cnt]=(edge){v,front[u]},front[u]=cnt;
}
int s[N];
long long int gans = 0;
int minn,maxx;
void dfs(int x,int fa)
{
for(int i=front[x];i;i=c[i].nxt)
{
if(c[i].v!=fa)
{
gans ^= 1LL*(s[x] ^s[c[i].v]) * 1LL*(s[x] ^s[c[i].v]);
chmin(minn,s[x]^s[c[i].v]);
chmax(maxx,s[x]^s[c[i].v]);
dfs(c[i].v,x);
}
}
}
int fa[N<<5];
int find(const int &x){return x==fa[x]?x:fa[x]=find(fa[x]);}
void MAIN()
{
minn=inf,maxx=0;
int n,m;
read(n,m);
memset(front,0,4*(n+3));
cnt=0;
memset(s,0,4*(n+3));
int x,y,z;
for(int i=1;i<n;++i)
{
read(x,y);
add(x,y),add(y,x);
}
for(int i=1;i<=n*32;++i) fa[i]=i;
for(int i=1;i<=m;++i)
{
read(x,y,z);
for(int j=0;j<16;++j)
{
if((z>>j)&1)
{
if(find(id(x,j,1))==find(id(y,j,0))&&find(id(x,j,0))==find(id(y,j,1)))
{
continue;
}
fa[find(id(x,j,1))]=find(id(y,j,0));
fa[find(id(x,j,0))]=find(id(y,j,1));
}
else
{
if(find(id(x,j,0))==find(id(y,j,0))&&find(id(x,j,1))==find(id(y,j,1)))
{
continue;
}
fa[find(id(x,j,0))]=find(id(y,j,0));
fa[find(id(x,j,1))]=find(id(y,j,1));
}
}
}
for(int i=1;i<=n;++i)
{
for(int j=0;j<16;++j)
{
if(find(id(i,j,0))==find(id(i,j,1)))
{
printf("Zero\n");
return;
}
}
}
for(int j=0;j<16;++j)
{
int cnt=0,tmp;
for(int i=1;i<=n;++i)
{
if(find(id(i,j,0))==id(i,j,0))
{
tmp=id(i,j,0);
++cnt;
}
if(find(id(i,j,1))==id(i,j,1))
{
tmp=id(i,j,1);
++cnt;
}
}
if(cnt>2)
{
printf("Multiple\n");
return;
}
for(int i=1;i<=n;++i)
{
if(find(id(i,j,1))==tmp)
{
s[i]^=1<<j;
}
}
}
gans = 0;
dfs(1,0);
printf("One\n");
printf("%Ild\n",gans);
}
int main()
{
int _ = 1;
while(_--) MAIN();
return 0;
}, In this Programming Language: C++, 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: Given an N*N matrix. Print the elements of the matrix in anticlockwise order (see the sample for better understanding).First line contains N.
N lines follow each containing N space seperated integers.
Constraints:-
2 <= N <= 500
1 <= Mat[i][j] <= 1000Output N*N integers in a single line separated by spaces, which are the elements of the matrix in anti-clockwise order.Sample Input
4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Sample output
1 5 9 13 14 15 16 12 8 4 3 2 6 10 11 7
Explanation:
We start from 1 , go down till 13 and then go right till 16 then go up till 4 , then we go left till 2 then down and so on in anti-clockwise fashion .
Sample Input
3
1 2 3
4 5 6
7 8 9
Sample output
1 4 7 8 9 6 3 2 5
, I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
class Main{
public static void main(String args[])throws IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(in.readLine());
int x, y, start, end, num=n, firstcond, secondcond, thirdcond, fourthcond, flag;
if(n%2!=0)
num++;
num = num/2;
int[][] a = new int[n][n];
for(x=0; x<n; x++){
String nextLine[] = in.readLine().split(" ");
for(y=0; y<n; y++){
a[x][y] = Integer.parseInt(nextLine[y]);
}
}
start = 0;
end = n-1;
while(num>=1){
flag=0;
firstcond = secondcond = thirdcond = fourthcond = 1;
for(x=start, y=start;
(firstcond==1 || secondcond==1 || thirdcond==1 || fourthcond==1) && (x>=start && y>=start && x<=end && y<=end);
){
System.out.print(a[x][y] + " ");
if(firstcond==1){
x++;
if(x==end+1){
firstcond=0;
x--;
y++;
}
}else if(secondcond==1){
y++;
if(y==end+1){
secondcond=0;
y--;
x--;
}
}else if(thirdcond==1){
x--;
if(x==start-1){
if(flag==0)
break;
thirdcond=0;
x++;
y--;
}
flag=1;
}else{
y--;
if(y==start){
fourthcond=0;
x++;
y++;
}
}
}
start++;
end--;
num--;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an N*N matrix. Print the elements of the matrix in anticlockwise order (see the sample for better understanding).First line contains N.
N lines follow each containing N space seperated integers.
Constraints:-
2 <= N <= 500
1 <= Mat[i][j] <= 1000Output N*N integers in a single line separated by spaces, which are the elements of the matrix in anti-clockwise order.Sample Input
4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Sample output
1 5 9 13 14 15 16 12 8 4 3 2 6 10 11 7
Explanation:
We start from 1 , go down till 13 and then go right till 16 then go up till 4 , then we go left till 2 then down and so on in anti-clockwise fashion .
Sample Input
3
1 2 3
4 5 6
7 8 9
Sample output
1 4 7 8 9 6 3 2 5
, I have written this Solution Code: n = int(input())
arr = []
for i in range(n):
j = input().split()
arr.append([int(xx) for xx in j])
def counterClockspiralPrint(m, n, arr) :
k = 0; l = 0
cnt = 0
total = m * n
while (k < m and l < n) :
if (cnt == total) :
break
for i in range(k, m) :
print(arr[i][l], end = " ")
cnt += 1
l += 1
if (cnt == total) :
break
for i in range (l, n) :
print( arr[m - 1][i], end = " ")
cnt += 1
m -= 1
if (cnt == total) :
break
if (k < m) :
for i in range(m - 1, k - 1, -1) :
print(arr[i][n - 1], end = " ")
cnt += 1
n -= 1
if (cnt == total) :
break
if (l < n) :
for i in range(n - 1, l - 1, -1) :
print( arr[k][i], end = " ")
cnt += 1
k += 1
counterClockspiralPrint(n, n, arr), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an N*N matrix. Print the elements of the matrix in anticlockwise order (see the sample for better understanding).First line contains N.
N lines follow each containing N space seperated integers.
Constraints:-
2 <= N <= 500
1 <= Mat[i][j] <= 1000Output N*N integers in a single line separated by spaces, which are the elements of the matrix in anti-clockwise order.Sample Input
4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Sample output
1 5 9 13 14 15 16 12 8 4 3 2 6 10 11 7
Explanation:
We start from 1 , go down till 13 and then go right till 16 then go up till 4 , then we go left till 2 then down and so on in anti-clockwise fashion .
Sample Input
3
1 2 3
4 5 6
7 8 9
Sample output
1 4 7 8 9 6 3 2 5
, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
#define N 1000
void counterClockspiralPrint( int m,
int n,
int arr[][N])
{
int i, k = 0, l = 0;
// k - starting row index
// m - ending row index
// l - starting column index
// n - ending column index
// i - iterator
// initialize the count
int cnt = 0;
// total number of
// elements in matrix
int total = m * n;
while (k < m && l < n)
{
if (cnt == total)
break;
// Print the first column
// from the remaining columns
for (i = k; i < m; ++i)
{
cout << arr[i][l] << " ";
cnt++;
}
l++;
if (cnt == total)
break;
// Print the last row from
// the remaining rows
for (i = l; i < n; ++i)
{
cout << arr[m - 1][i] << " ";
cnt++;
}
m--;
if (cnt == total)
break;
// Print the last column
// from the remaining columns
if (k < m)
{
for (i = m - 1; i >= k; --i)
{
cout << arr[i][n - 1] << " ";
cnt++;
}
n--;
}
if (cnt == total)
break;
// Print the first row
// from the remaining rows
if (l < n)
{
for (i = n - 1; i >= l; --i)
{
cout << arr[k][i] << " ";
cnt++;
}
k++;
}
}
}
int main()
{
int n;
cin>>n;
int arr[n][N];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin>>arr[i][j];
}}
counterClockspiralPrint(n,n, arr);
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an N*N matrix. Print the elements of the matrix in anticlockwise order (see the sample for better understanding).First line contains N.
N lines follow each containing N space seperated integers.
Constraints:-
2 <= N <= 500
1 <= Mat[i][j] <= 1000Output N*N integers in a single line separated by spaces, which are the elements of the matrix in anti-clockwise order.Sample Input
4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Sample output
1 5 9 13 14 15 16 12 8 4 3 2 6 10 11 7
Explanation:
We start from 1 , go down till 13 and then go right till 16 then go up till 4 , then we go left till 2 then down and so on in anti-clockwise fashion .
Sample Input
3
1 2 3
4 5 6
7 8 9
Sample output
1 4 7 8 9 6 3 2 5
, I have written this Solution Code: function printAntiClockWise(mat)
{
let i, k = 0, l = 0;
let m = N;
let n = N;
let cnt = 0, total = m*n;
while(k < m && l < n)
{
if (cnt == total)
break;
// Print the first column
// from the remaining columns
for (i = k; i < m; ++i)
{
process.stdout.write(mat[i][l] + " ");
cnt++;
}
l++;
if (cnt == total)
break;
// Print the last row from
// the remaining rows
for (i = l; i < n; ++i)
{
process.stdout.write(mat[m - 1][i] + " ");
cnt++;
}
m--;
if (cnt == total)
break;
// Print the last column
// from the remaining columns
if (k < m)
{
for (i = m - 1; i >= k; --i)
{
process.stdout.write(mat[i][n - 1] + " ");
cnt++;
}
n--;
}
if (cnt == total)
break;
// Print the first row
// from the remaining rows
if (l < n)
{
for (i = n - 1; i >= l; --i)
{
process.stdout.write(mat[k][i] + " ");
cnt++;
}
k++;
}
}
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the scores of a cricket player in n innings and a target score k, you can choose an inning score x from the list, erase x from the list, and subtract the value of x from all the remaining innings scores. Find if there is a sequence of n-1 operations such that, after applying the operations, the only remaining inning score is equal to a target score k.The first line contains two integers n and k, the number of integers in the list, and the target value, respectively.
The second line contains the n innings a<sub>1</sub>, a<sub>2</sub>, a<sub>3</sub>...a<sub>n</sub>.
<b>Constraints </b>
2 ≤ n ≤ 2*10<sup>5</sup>
1 ≤ k ≤ 10<sup>9</sup>
-10<sup>9</sup> ≤ a[i] ≤ 10<sup>9</sup>Print "YES" if there is some sequence of nβ1 operations such that, after applying the operations, the only remaining inning score is equal to k. Else print "NO".Input:
4 5
4 2 2 7
Output:
YES
Explanation :
We have the list {4, 2, 2, 7}, and we have the target k=5. One way to achieve it is the following: first, we choose the third element, obtaining the list {2, 0, 5}. Next, we choose the first element, obtaining the list {β2, 3}. Finally, we choose the first element, obtaining the list {5}., I have written this Solution Code: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
int t;
t=1;
while(t--) {
int n, a;
cin >> n >> a;
vector<int> v(n);
for(int& x : v) cin >> x;
bool ans = false;
if(n == 1) ans = (v[0] == a);
else {
sort(v.begin(), v.end());
int i = 0;
int j = 1;
while(j < n and i < n) {
if(v[i] + abs(a) == v[j]) {
ans = true;
break;
}
else if(v[i] + abs(a) < v[j]) ++i;
else ++j;
}
}
cout << (ans? "YES" : "NO") << '\n';
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the marks of N students, your task is to calculate the average of the marks obtained.First line of input contains a single integer N. The next line contains N space separated integers containing the marks of the students.
Constraints:-
1 <= N <= 1000
1 <= marks <= 1000Print the floor of the average of marks obtained.Sample Input:-
4
1 2 3 4
Sample Output:-
2
Sample Input:-
3
5 5 5
Sample Output:-
5, I have written this Solution Code: n=int(input())
a=list(map(int,input().split()))
print(sum(a)//n), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the marks of N students, your task is to calculate the average of the marks obtained.First line of input contains a single integer N. The next line contains N space separated integers containing the marks of the students.
Constraints:-
1 <= N <= 1000
1 <= marks <= 1000Print the floor of the average of marks obtained.Sample Input:-
4
1 2 3 4
Sample Output:-
2
Sample Input:-
3
5 5 5
Sample Output:-
5, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.lang.*;
class Main {
public static void main (String[] args)throws IOException {
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();
}
System.out.print(Average_Marks(a,n));
}
static int Average_Marks(int marks[],int N){
int sum=0;
for(int i=0;i<N;i++){
sum+=marks[i];
}
return sum/N;
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice wants to go to Bob's house. The location of their houses is given on a 2-D coordinate system. There are a total of 8 directions:
North - Directly above
South - Directly below
East - To the right
West - To the left
North East - In between north and east
North West - In between north and west
South East - In between south and east
South West - In between south and west
Find the direction in which Alice must go to reach Bob's house.There are two lines of input. The first line contains the x and y coordinate of Alice's house. The second line contains x and y coordinate of Bob's house. It is given that these two locations are different.
-100 <= Coordinates <= 100Print a single string denoting the direction in which Alice must move to reach Bob's house.Sample Input 1:
2 5
11 25
Sample Output 1:
North East
Sample Input 2:
23 12
-85 12
Sample Output 2:
West, I have written this Solution Code: x0,y0 =map(int,input().split(" "))
x1,y1 = map(int,input().split(" "))
N = "North " if y0<y1 else "South " if y0> y1 else ""
E = "East " if x0<x1 else "West " if x0> x1 else ""
print(N+E), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice wants to go to Bob's house. The location of their houses is given on a 2-D coordinate system. There are a total of 8 directions:
North - Directly above
South - Directly below
East - To the right
West - To the left
North East - In between north and east
North West - In between north and west
South East - In between south and east
South West - In between south and west
Find the direction in which Alice must go to reach Bob's house.There are two lines of input. The first line contains the x and y coordinate of Alice's house. The second line contains x and y coordinate of Bob's house. It is given that these two locations are different.
-100 <= Coordinates <= 100Print a single string denoting the direction in which Alice must move to reach Bob's house.Sample Input 1:
2 5
11 25
Sample Output 1:
North East
Sample Input 2:
23 12
-85 12
Sample Output 2:
West, 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 = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
void solve(){
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
if(x1 == x2){
if(y1 < y2)
cout << "North";
else
cout << "South";
}
else if(y1 == y2){
if(x1 < x2)
cout << "East";
else
cout << "West";
}
else if(x1 < x2 && y1 < y2)
cout << "North East";
else if(x1 < x2 && y1 > y2)
cout << "South East";
else if(x1 > x2 && y1 < y2)
cout << "North West";
else
cout << "South West";
}
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: Alice wants to go to Bob's house. The location of their houses is given on a 2-D coordinate system. There are a total of 8 directions:
North - Directly above
South - Directly below
East - To the right
West - To the left
North East - In between north and east
North West - In between north and west
South East - In between south and east
South West - In between south and west
Find the direction in which Alice must go to reach Bob's house.There are two lines of input. The first line contains the x and y coordinate of Alice's house. The second line contains x and y coordinate of Bob's house. It is given that these two locations are different.
-100 <= Coordinates <= 100Print a single string denoting the direction in which Alice must move to reach Bob's house.Sample Input 1:
2 5
11 25
Sample Output 1:
North East
Sample Input 2:
23 12
-85 12
Sample Output 2:
West, 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 x1, y1, x2, y2;
x1=sc.nextInt();
y1=sc.nextInt();
x2=sc.nextInt();
y2=sc.nextInt();
if(x1 == x2){
if(y1 < y2)
System.out.print("North");
else
System.out.print("South");
}
else if(y1 == y2){
if(x1 < x2)
System.out.print("East");
else
System.out.print("West");
}
else if(x1 < x2 && y1 < y2)
System.out.print("North East");
else if(x1 < x2 && y1 > y2)
System.out.print("South East");
else if(x1 > x2 && y1 < y2)
System.out.print("North West");
else
System.out.print("South West");
}
}, 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 all the even integer from 1 to N.<b>User task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the functions <b>For_Loop()</b> that take the integer n as a parameter.
</b>Constraints:</b>
1 <= n <= 100
<b>Note:</b>
<i>But there is a catch here, given user function has already code in it which may or may not be correct, now you need to figure out these and correct them if it is required</i>Print all the even numbers from 1 to n. (print all the numbers in the same line, space-separated)Sample Input:-
5
Sample Output:-
2 4
Sample Input:-
6
Sample Output:-
2 4 6, I have written this Solution Code: def For_Loop(n):
string = ""
for i in range(1, n+1):
if i % 2 == 0:
string += "%s " % i
return string
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, your task is to print all the even integer from 1 to N.<b>User task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the functions <b>For_Loop()</b> that take the integer n as a parameter.
</b>Constraints:</b>
1 <= n <= 100
<b>Note:</b>
<i>But there is a catch here, given user function has already code in it which may or may not be correct, now you need to figure out these and correct them if it is required</i>Print all the even numbers from 1 to n. (print all the numbers in the same line, space-separated)Sample Input:-
5
Sample Output:-
2 4
Sample Input:-
6
Sample Output:-
2 4 6, I have written this Solution Code: public static void For_Loop(int n){
for(int i=2;i<=n;i+=2){
System.out.print(i+" ");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, your task is to convert the number into a single digit by repeatedly replacing the number N with its sum of digits until the number becomes a single digit.The input contains a single integer N.
Constraints:-
1 <= N <= 100000Print the single digit after performing the given operation.Sample Input:-
987
Sample Output:-
6
Explanation:-
987 - > 9 + 8 + 7 => 24 = 2 + 4 => 6
Sample Input:-
91
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)
);
int n = Integer.parseInt(br.readLine());
int sum =0;
while(sum>9 || n>0){
if (n == 0) {
n = sum;
sum = 0;
}
sum += n%10;
n /= 10;
}
System.out.println(sum);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, your task is to convert the number into a single digit by repeatedly replacing the number N with its sum of digits until the number becomes a single digit.The input contains a single integer N.
Constraints:-
1 <= N <= 100000Print the single digit after performing the given operation.Sample Input:-
987
Sample Output:-
6
Explanation:-
987 - > 9 + 8 + 7 => 24 = 2 + 4 => 6
Sample Input:-
91
Sample Output:-
1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
while(n>9){
int p = n;
int sum=0;
while(p>0){
sum+=p%10;
p/=10;
}
n=sum;
}
cout<<n;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, your task is to convert the number into a single digit by repeatedly replacing the number N with its sum of digits until the number becomes a single digit.The input contains a single integer N.
Constraints:-
1 <= N <= 100000Print the single digit after performing the given operation.Sample Input:-
987
Sample Output:-
6
Explanation:-
987 - > 9 + 8 + 7 => 24 = 2 + 4 => 6
Sample Input:-
91
Sample Output:-
1, I have written this Solution Code: def singleDigit(n):
while(n>9):
p = n
sumDigit = 0
while(p>0):
sumDigit += p%10
p//=10
n = sumDigit
return sumDigit
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of n pairs of integers. Your task is to sort the array on the basis of the first element of pairs in descending order. If the first element is equal in two or more pairs then give preference to the pair that has a greater second element value.<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>SortPair()</b> that takes the array of pairs and the integer N(size of the array) as a parameter.
<b>Custom Input <b/>
The first line of input will be a single integer N. The next line of input contains 2*N space-separated integers where unique adjacent elements are pairs. Custom input for 1st sample:-
4
1 2 3 4 5 6 7 8
<b>Constraints:-</b>
1<=N<=10<sup>3</sup>
1<=value<=10<sup>5</sup>Return the sorted array of pairs.Sample Input 1:
4
(1, 2), (3, 4), (5, 6), (7, 8)
Sample Output 1:
(7, 8), (5, 6), (3, 4), (1, 2)
Sample Input 2:
3
(1, 1), (2, 2), (3, 3)
Sample Output 2:
(3, 3), (2, 2), (1, 1)
Sample Input 3:
3
(1, 1), (1, 2), (3, 3)
Sample Output 3:
(3, 3), (1, 2), (1, 1)
<b>Explanation :</b>
(1,2) and (1,1) have the same first element. But (1,2) has a greater second element so (1,2) comes before (1,1) in a sorted array.
, I have written this Solution Code: def SortPair(items,n):
items.sort(reverse = True)
return items, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of n pairs of integers. Your task is to sort the array on the basis of the first element of pairs in descending order. If the first element is equal in two or more pairs then give preference to the pair that has a greater second element value.<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>SortPair()</b> that takes the array of pairs and the integer N(size of the array) as a parameter.
<b>Custom Input <b/>
The first line of input will be a single integer N. The next line of input contains 2*N space-separated integers where unique adjacent elements are pairs. Custom input for 1st sample:-
4
1 2 3 4 5 6 7 8
<b>Constraints:-</b>
1<=N<=10<sup>3</sup>
1<=value<=10<sup>5</sup>Return the sorted array of pairs.Sample Input 1:
4
(1, 2), (3, 4), (5, 6), (7, 8)
Sample Output 1:
(7, 8), (5, 6), (3, 4), (1, 2)
Sample Input 2:
3
(1, 1), (2, 2), (3, 3)
Sample Output 2:
(3, 3), (2, 2), (1, 1)
Sample Input 3:
3
(1, 1), (1, 2), (3, 3)
Sample Output 3:
(3, 3), (1, 2), (1, 1)
<b>Explanation :</b>
(1,2) and (1,1) have the same first element. But (1,2) has a greater second element so (1,2) comes before (1,1) in a sorted array.
, I have written this Solution Code:
static Pair[] SortPair(Pair arr[], int n)
{
// Comparator to sort the pair according to second element
Arrays.sort(arr, new Comparator<Pair>() {
@Override public int compare(Pair p1, Pair p2)
{
if(p1.x==p2.x){
return p2.y-p1.y;
}
return p2.x-p1.x;
}
});
return arr;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, you need to count the integers which are multiple of N between 1 to 100. Return the count.<b>User task:</b>
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>countMultiples()</b> which contains N as a parameter.
<b>Constraints:</b>
1 <= N <= 100You need to return the count.Sample Input:
3
Sample Output:
33
Sample Input:
4
Sample Output:
25, I have written this Solution Code: def countMultiples(N):
return int(100/N)
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, you need to count the integers which are multiple of N between 1 to 100. Return the count.<b>User task:</b>
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>countMultiples()</b> which contains N as a parameter.
<b>Constraints:</b>
1 <= N <= 100You need to return the count.Sample Input:
3
Sample Output:
33
Sample Input:
4
Sample Output:
25, I have written this Solution Code: static int countMultiples(int N)
{
int i = 1, count = 0;
while(i < 101){
if(i % N == 0)
count++;
i++;
}
return count;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, you need to count the integers which are multiple of N between 1 to 100. Return the count.<b>User task:</b>
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>countMultiples()</b> which contains N as a parameter.
<b>Constraints:</b>
1 <= N <= 100You need to return the count.Sample Input:
3
Sample Output:
33
Sample Input:
4
Sample Output:
25, I have written this Solution Code:
int countMultiples(int n){
return (100/n);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, you need to count the integers which are multiple of N between 1 to 100. Return the count.<b>User task:</b>
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>countMultiples()</b> which contains N as a parameter.
<b>Constraints:</b>
1 <= N <= 100You need to return the count.Sample Input:
3
Sample Output:
33
Sample Input:
4
Sample Output:
25, I have written this Solution Code:
int countMultiples(int n){
return (100/n);
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Internet download speed is often expressed in bit per second whereas file size is expressed in Bytes. It is known that 1 Byte = 8 bits. Given file size in megabytes(MB) and internet speed in megabits per seconds(Mbps), find the time taken in seconds to download the file.The only line of input contains two integers denoting the file size in MB and download speed in Mbps.
1 <= file size <= 1000
1 <= download speed <= 1000Print a single integer denoting the time taken to download the file in seconds.
It is guaranteed that the result will be an integer.Sample Input:
10 16
Sample Output:
5, 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 = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
void solve(){
int f, s;
cin >> f >> s;
cout << (8*f)/s << 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: Internet download speed is often expressed in bit per second whereas file size is expressed in Bytes. It is known that 1 Byte = 8 bits. Given file size in megabytes(MB) and internet speed in megabits per seconds(Mbps), find the time taken in seconds to download the file.The only line of input contains two integers denoting the file size in MB and download speed in Mbps.
1 <= file size <= 1000
1 <= download speed <= 1000Print a single integer denoting the time taken to download the file in seconds.
It is guaranteed that the result will be an integer.Sample Input:
10 16
Sample Output:
5, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int f = sc.nextInt();
int s = sc.nextInt();
int ans = (8*f)/s;
System.out.print(ans);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Internet download speed is often expressed in bit per second whereas file size is expressed in Bytes. It is known that 1 Byte = 8 bits. Given file size in megabytes(MB) and internet speed in megabits per seconds(Mbps), find the time taken in seconds to download the file.The only line of input contains two integers denoting the file size in MB and download speed in Mbps.
1 <= file size <= 1000
1 <= download speed <= 1000Print a single integer denoting the time taken to download the file in seconds.
It is guaranteed that the result will be an integer.Sample Input:
10 16
Sample Output:
5, I have written this Solution Code: a = list(map(int,input().strip().split()))[:2]
print(int((a[0]*8)/a[1])), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is building a tower with N disks of sizes 1 to N.
The rules for building the tower are simple:-
*Every day you are provided with one disk having distinct size.
*The disk with larger sizes should be placed at the bottom of the tower.
*The disk with smaller sizes should be placed at the top of the tower.
*You cannot put a new disk on the top of the tower until all the larger disks that are given to you get placed.
Your task is to print N lines denoting the disk sizes that can be put on the tower on the i<sup>th</sup> day.The first line of input contains a single integer N. The next line of input contains N space separated integers depicting the size of the discs.
Constraints:-
1 <= N <= 100000
1 <= Size <= NPrint N lines. In the ith line, print the size of disks that can be placed on the top of the tower in descending order of the disk sizes.
If on the ith day no disks can be placed, then leave that line empty.Sample Input:-
5
4 5 1 2 3
Sample Output:-
5 4
3 2 1
Explanation
On the first day, the disk of size 4 is given. But you cannot put the disk on the bottom of the tower as a disk of size 5 is still remaining.
On the second day, the disk of size 5 will be given so now the disk of sizes 5 and 4 can be placed on the tower.
On the third and fourth days, disks cannot be placed on the tower as the disk of 3 needs to be given yet. Therefore, these lines are empty.
On the fifth day, all the disks of sizes 3, 2, and 1 can be placed on the top of the tower.
Sample Input:-
3
3 2 1
Sample Output:-
3
2
1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main(String args[])throws IOException
{
int n;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
n=Integer.parseInt(br.readLine());
int a[]=new int[n];
StringTokenizer st=new StringTokenizer(br.readLine());
for(int i=0;i<n;i++)
a[i]=Integer.parseInt(st.nextToken());
boolean vis[]=new boolean[n+1];
int max=n;
StringBuilder sb=new StringBuilder();
for(int i=0;i<n;i++)
{
vis[a[i]]=true;
if(vis[max])
{
while(vis[max])
{
sb.append(max).append(" ");
max--;
}
}
sb.append("\n");
}
System.out.println(sb);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is building a tower with N disks of sizes 1 to N.
The rules for building the tower are simple:-
*Every day you are provided with one disk having distinct size.
*The disk with larger sizes should be placed at the bottom of the tower.
*The disk with smaller sizes should be placed at the top of the tower.
*You cannot put a new disk on the top of the tower until all the larger disks that are given to you get placed.
Your task is to print N lines denoting the disk sizes that can be put on the tower on the i<sup>th</sup> day.The first line of input contains a single integer N. The next line of input contains N space separated integers depicting the size of the discs.
Constraints:-
1 <= N <= 100000
1 <= Size <= NPrint N lines. In the ith line, print the size of disks that can be placed on the top of the tower in descending order of the disk sizes.
If on the ith day no disks can be placed, then leave that line empty.Sample Input:-
5
4 5 1 2 3
Sample Output:-
5 4
3 2 1
Explanation
On the first day, the disk of size 4 is given. But you cannot put the disk on the bottom of the tower as a disk of size 5 is still remaining.
On the second day, the disk of size 5 will be given so now the disk of sizes 5 and 4 can be placed on the tower.
On the third and fourth days, disks cannot be placed on the tower as the disk of 3 needs to be given yet. Therefore, these lines are empty.
On the fifth day, all the disks of sizes 3, 2, and 1 can be placed on the top of the tower.
Sample Input:-
3
3 2 1
Sample Output:-
3
2
1, I have written this Solution Code: def Solve(arr):
size = len(arr)
queue = {}
for i in arr:
queue[i] = True
placed = []
if i == size:
placed.append(i)
size -= 1
while size in queue:
placed.append(size)
size -= 1
yield placed
N = int(input())
arr = list(map(int, input().split()))
out_ = Solve(arr)
for i_out_ in out_:
print(' '.join(map(str, i_out_))), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is building a tower with N disks of sizes 1 to N.
The rules for building the tower are simple:-
*Every day you are provided with one disk having distinct size.
*The disk with larger sizes should be placed at the bottom of the tower.
*The disk with smaller sizes should be placed at the top of the tower.
*You cannot put a new disk on the top of the tower until all the larger disks that are given to you get placed.
Your task is to print N lines denoting the disk sizes that can be put on the tower on the i<sup>th</sup> day.The first line of input contains a single integer N. The next line of input contains N space separated integers depicting the size of the discs.
Constraints:-
1 <= N <= 100000
1 <= Size <= NPrint N lines. In the ith line, print the size of disks that can be placed on the top of the tower in descending order of the disk sizes.
If on the ith day no disks can be placed, then leave that line empty.Sample Input:-
5
4 5 1 2 3
Sample Output:-
5 4
3 2 1
Explanation
On the first day, the disk of size 4 is given. But you cannot put the disk on the bottom of the tower as a disk of size 5 is still remaining.
On the second day, the disk of size 5 will be given so now the disk of sizes 5 and 4 can be placed on the tower.
On the third and fourth days, disks cannot be placed on the tower as the disk of 3 needs to be given yet. Therefore, these lines are empty.
On the fifth day, all the disks of sizes 3, 2, and 1 can be placed on the top of the tower.
Sample Input:-
3
3 2 1
Sample Output:-
3
2
1, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
vector<vector<int> > SolveTower (int N, vector<int> a) {
// Write your code here
vector<vector<int> > ans;
int done = N;
priority_queue<int> pq;
for(auto x: a){
pq.push(x);
vector<int> aux;
while(!pq.empty() && pq.top() == done){
aux.push_back(done);
pq.pop();
done--;
}
ans.push_back(aux);
}
sort(a.begin(), a.end());
a.resize(unique(a.begin(), a.end()) - a.begin());
assert(a.size() == N);
return ans;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N;
cin >> N;
assert(1 <= N && N <= 1e6);
vector<int> a(N);
for(int i_a = 0; i_a < N; i_a++)
{
cin >> a[i_a];
}
vector<vector<int> > out_;
out_ = SolveTower(N, a);
for(int i = 0; i < out_.size(); i++){
for(int j = 0; j < out_[i].size(); j++){
cout << out_[i][j] << " ";
}
cout << "\n";
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Newton's garden has N apple trees. Initially, there are A<sub>i</sub> apples attached to the ith tree. Also, there are M apples which newton has to attach to these tress for testing gravity laws.
In one minute, at most B<sub>i</sub> apples fall from the ith tree.
Help newton find the minimum time he has to wait after which he can safely sit under any apple tree.The first line contains two space-separated integers β N and M indicating the number of apple trees and the number of apples to be attached.
Each of the next N lines contains two integers A<sub>i</sub> and B<sub>i</sub> specifying the initial count of apples and rate of fall of apples per minute for ith tree.
<b> Constraints: </b>
1 <= N <= 2*10<sup>5</sup>
0 <= A<sub>i</sub> <= 10<sup>6</sup>
1 <= M, B<sub>i</sub> <= 10<sup>6</sup>Output minimum time Newton has to waitInput:
3 6
4 3
7 4
1 5
Output:
2
Explanation:
Attach 2, 1, 3 apples to 1st, 2nd, 3rd tree respectively. Then, 2, 2, 1 minutes are required for all apples to fall from 1st, 2nd, 3rd tree respectively. So, Wait time is max(2, 2, 1) = 2., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N = 2*1e5+5;
ll n,m;
vector<ll> a(N),b(N);
bool possible(ll time) {
ll lim = 0;
for(int i=0 ; i<n ; i++) lim += b[i] * time;
ll tot = m;
for(int i=0 ; i<n ; i++) tot += a[i];
if (tot > lim) return false;
for(int i=0 ; i<n ; i++) if (a[i] > b[i]*time) return false;
return true;
}
int main(){
cin >> n >> m;
for(int i=0 ; i<n ; i++){
cin >> a[i] >> b[i];
}
ll lo = 1, hi = 2*1e6+1000;
while(hi - lo > 1) {
ll mid = (hi+lo)/2;
if (possible(mid)){
hi = mid;
}else{
lo = mid;
}
}
cout << hi << endl;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n.
Constraints:-
1 <= n <= 10000000Return number of primes less than or equal to nSample Input
5
Sample Output
3
Explanation:-
2 3 and 5 are the required primes.
Sample Input
5000
Sample Output
669, I have written this Solution Code: #include <bits/stdc++.h>
// #define ll long long
using namespace std;
#define ma 10000001
bool a[ma];
int main()
{
int n;
cin>>n;
for(int i=0;i<=n;i++){
a[i]=false;
}
for(int i=2;i<=n;i++){
if(a[i]==false){
for(int j=i+i;j<=n;j+=i){
a[j]=true;
}
}
}
int cnt=0;
for(int i=2;i<=n;i++){
if(a[i]==false){cnt++;}
}
cout<<cnt;
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n.
Constraints:-
1 <= n <= 10000000Return number of primes less than or equal to nSample Input
5
Sample Output
3
Explanation:-
2 3 and 5 are the required primes.
Sample Input
5000
Sample Output
669, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.lang.Math;
class Main {
public static void main (String[] args)
throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
long n = Integer.parseInt(br.readLine());
long i=2,j,count,noOfPrime=0;
if(n<=1)
System.out.println("0");
else{
while(i<=n)
{
count=0;
for(j=2; j<=Math.sqrt(i); j++)
{
if( i%j == 0 ){
count++;
break;
}
}
if(count==0){
noOfPrime++;
}
i++;
}
System.out.println(noOfPrime);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n.
Constraints:-
1 <= n <= 10000000Return number of primes less than or equal to nSample Input
5
Sample Output
3
Explanation:-
2 3 and 5 are the required primes.
Sample Input
5000
Sample Output
669, I have written this Solution Code: function numberOfPrimes(N)
{
let arr = new Array(N+1);
for(let i = 0; i <= N; i++)
arr[i] = 0;
for(let i=2; i<= N/2; i++)
{
if(arr[i] === -1)
{
continue;
}
let p = i;
for(let j=2; p*j<= N; j++)
{
arr[p*j] = -1;
}
}
//console.log(arr);
let count = 0;
for(let i=2; i<= N; i++)
{
if(arr[i] === 0)
{
count++;
}
}
//console.log(arr);
return count;
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n.
Constraints:-
1 <= n <= 10000000Return number of primes less than or equal to nSample Input
5
Sample Output
3
Explanation:-
2 3 and 5 are the required primes.
Sample Input
5000
Sample Output
669, I have written this Solution Code: import math
n = int(input())
n=n+1
if n<3:
print(0)
else:
primes=[1]*(n//2)
for i in range(3,int(math.sqrt(n))+1,2):
if primes[i//2]:primes[i*i//2::i]=[0]*((n-i*i-1)//(2*i)+1)
print(sum(primes)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Your task is to implement a stack using a linked list and perform given queries
Note:-if stack is already empty than pop operation will do nothing and 0 will be printed as a top element of stack if it is empty.User task:
Since this will be a functional problem, you don't have to take input. You just have to complete the functions:
<b>push()</b>:- that takes the integer to be added as a parameter.
<b>pop()</b>:- that takes no parameter.
<b>top()</b> :- that takes no parameter.
Constraints:
1 <= N(number of queries) <= 10<sup>3</sup>You don't need to print anything else other than in top function in which you require to print the top most element of your stack in a new line, if the stack is empty you just need to print 0.Input:
7
push 1
push 2
top
pop
top
pop
top
Output:
2
1
0
, I have written this Solution Code:
Node top = null;
public void push(int x)
{
Node temp = new Node(x);
temp.next = top;
top = temp;
}
public void pop()
{
if (top == null) {
}
else {
top = (top).next;}
}
public void top()
{
// check for stack underflow
if (top == null) {
System.out.println("0");
}
else {
Node temp = top;
System.out.println(temp.val);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: void fizzbuzz(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){cout<<"FizzBuzz"<<" ";}
else if(i%5==0){cout<<"Buzz ";}
else if(i%3==0){cout<<"Fizz ";}
else{cout<<i<<" ";}
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int x= sc.nextInt();
fizzbuzz(x);
}
static void fizzbuzz(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){System.out.print("FizzBuzz ");}
else if(i%5==0){System.out.print("Buzz ");}
else if(i%3==0){System.out.print("Fizz ");}
else{System.out.print(i+" ");}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: def fizzbuzz(n):
for i in range (1,n+1):
if (i%3==0 and i%5==0):
print("FizzBuzz",end=' ')
elif i%3==0:
print("Fizz",end=' ')
elif i%5==0:
print("Buzz",end=' ')
else:
print(i,end=' '), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: void fizzbuzz(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){printf("FizzBuzz ");}
else if(i%5==0){printf("Buzz ");}
else if(i%3==0){printf("Fizz ");}
else{printf("%d ",i);}
}
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: def compound_interest(principle, rate, time):
Amount = principle * (pow((1 + rate / 100), time))
CI = Amount - principle
print( '%.2f'%CI)
principle,rate,time=map(int, input().split())
compound_interest(principle,rate,time), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: function calculateCI(P, R, T)
{
let interest = P * (Math.pow(1.0 + R/100.0, T) - 1);
return interest.toFixed(2);
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int p,r,t;
cin>>p>>r>>t;
double rate= (float)r/100;
double amt = (float)p*(pow(1+rate,t));
cout << fixed << setprecision(2) << (amt - p);
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.lang.Math;
class Main {
public static void main (String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] s= br.readLine().split(" ");
double[] darr = new double[s.length];
for(int i=0;i<s.length;i++){
darr[i] = Double.parseDouble(s[i]);
}
double ans = darr[0]*Math.pow(1+darr[1]/100,darr[2])-darr[0];
System.out.printf("%.2f",ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Let us start our journey by creating a 'PROFILE' table for storing the data of the users of our platform. Create a table profile with 3 fields ( USERNAME VARCHAR (24), FULL_NAME VARCHAR (72), HEADLINE VARCHAR (72) ).
<schema>[{'name': 'PROFILE', 'columns': [{'name': 'USERNAME', 'type': 'VARCHAR (24)'}, {'name': 'FULL_NAME', 'type': 'VARCHAR (72)'}, {'name': 'HEADLINE', 'type': 'VARCHAR (72)'}]}]</schema>NA - User input does not work for this question.The output will be generated in a 2-D array format consisting of rows and columns.nan, I have written this Solution Code: CREATE TABLE PROFILE (
USERNAME VARCHAR(24),
FULL_NAME VARCHAR(72),
HEADLINE VARCHAR(72)
);
, In this Programming Language: SQL, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an N*N matrix. Print the elements of the matrix in anticlockwise order (see the sample for better understanding).First line contains N.
N lines follow each containing N space seperated integers.
Constraints:-
2 <= N <= 500
1 <= Mat[i][j] <= 1000Output N*N integers in a single line separated by spaces, which are the elements of the matrix in anti-clockwise order.Sample Input
4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Sample output
1 5 9 13 14 15 16 12 8 4 3 2 6 10 11 7
Explanation:
We start from 1 , go down till 13 and then go right till 16 then go up till 4 , then we go left till 2 then down and so on in anti-clockwise fashion .
Sample Input
3
1 2 3
4 5 6
7 8 9
Sample output
1 4 7 8 9 6 3 2 5
, I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
class Main{
public static void main(String args[])throws IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(in.readLine());
int x, y, start, end, num=n, firstcond, secondcond, thirdcond, fourthcond, flag;
if(n%2!=0)
num++;
num = num/2;
int[][] a = new int[n][n];
for(x=0; x<n; x++){
String nextLine[] = in.readLine().split(" ");
for(y=0; y<n; y++){
a[x][y] = Integer.parseInt(nextLine[y]);
}
}
start = 0;
end = n-1;
while(num>=1){
flag=0;
firstcond = secondcond = thirdcond = fourthcond = 1;
for(x=start, y=start;
(firstcond==1 || secondcond==1 || thirdcond==1 || fourthcond==1) && (x>=start && y>=start && x<=end && y<=end);
){
System.out.print(a[x][y] + " ");
if(firstcond==1){
x++;
if(x==end+1){
firstcond=0;
x--;
y++;
}
}else if(secondcond==1){
y++;
if(y==end+1){
secondcond=0;
y--;
x--;
}
}else if(thirdcond==1){
x--;
if(x==start-1){
if(flag==0)
break;
thirdcond=0;
x++;
y--;
}
flag=1;
}else{
y--;
if(y==start){
fourthcond=0;
x++;
y++;
}
}
}
start++;
end--;
num--;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an N*N matrix. Print the elements of the matrix in anticlockwise order (see the sample for better understanding).First line contains N.
N lines follow each containing N space seperated integers.
Constraints:-
2 <= N <= 500
1 <= Mat[i][j] <= 1000Output N*N integers in a single line separated by spaces, which are the elements of the matrix in anti-clockwise order.Sample Input
4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Sample output
1 5 9 13 14 15 16 12 8 4 3 2 6 10 11 7
Explanation:
We start from 1 , go down till 13 and then go right till 16 then go up till 4 , then we go left till 2 then down and so on in anti-clockwise fashion .
Sample Input
3
1 2 3
4 5 6
7 8 9
Sample output
1 4 7 8 9 6 3 2 5
, I have written this Solution Code: n = int(input())
arr = []
for i in range(n):
j = input().split()
arr.append([int(xx) for xx in j])
def counterClockspiralPrint(m, n, arr) :
k = 0; l = 0
cnt = 0
total = m * n
while (k < m and l < n) :
if (cnt == total) :
break
for i in range(k, m) :
print(arr[i][l], end = " ")
cnt += 1
l += 1
if (cnt == total) :
break
for i in range (l, n) :
print( arr[m - 1][i], end = " ")
cnt += 1
m -= 1
if (cnt == total) :
break
if (k < m) :
for i in range(m - 1, k - 1, -1) :
print(arr[i][n - 1], end = " ")
cnt += 1
n -= 1
if (cnt == total) :
break
if (l < n) :
for i in range(n - 1, l - 1, -1) :
print( arr[k][i], end = " ")
cnt += 1
k += 1
counterClockspiralPrint(n, n, arr), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an N*N matrix. Print the elements of the matrix in anticlockwise order (see the sample for better understanding).First line contains N.
N lines follow each containing N space seperated integers.
Constraints:-
2 <= N <= 500
1 <= Mat[i][j] <= 1000Output N*N integers in a single line separated by spaces, which are the elements of the matrix in anti-clockwise order.Sample Input
4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Sample output
1 5 9 13 14 15 16 12 8 4 3 2 6 10 11 7
Explanation:
We start from 1 , go down till 13 and then go right till 16 then go up till 4 , then we go left till 2 then down and so on in anti-clockwise fashion .
Sample Input
3
1 2 3
4 5 6
7 8 9
Sample output
1 4 7 8 9 6 3 2 5
, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
#define N 1000
void counterClockspiralPrint( int m,
int n,
int arr[][N])
{
int i, k = 0, l = 0;
// k - starting row index
// m - ending row index
// l - starting column index
// n - ending column index
// i - iterator
// initialize the count
int cnt = 0;
// total number of
// elements in matrix
int total = m * n;
while (k < m && l < n)
{
if (cnt == total)
break;
// Print the first column
// from the remaining columns
for (i = k; i < m; ++i)
{
cout << arr[i][l] << " ";
cnt++;
}
l++;
if (cnt == total)
break;
// Print the last row from
// the remaining rows
for (i = l; i < n; ++i)
{
cout << arr[m - 1][i] << " ";
cnt++;
}
m--;
if (cnt == total)
break;
// Print the last column
// from the remaining columns
if (k < m)
{
for (i = m - 1; i >= k; --i)
{
cout << arr[i][n - 1] << " ";
cnt++;
}
n--;
}
if (cnt == total)
break;
// Print the first row
// from the remaining rows
if (l < n)
{
for (i = n - 1; i >= l; --i)
{
cout << arr[k][i] << " ";
cnt++;
}
k++;
}
}
}
int main()
{
int n;
cin>>n;
int arr[n][N];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin>>arr[i][j];
}}
counterClockspiralPrint(n,n, arr);
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an N*N matrix. Print the elements of the matrix in anticlockwise order (see the sample for better understanding).First line contains N.
N lines follow each containing N space seperated integers.
Constraints:-
2 <= N <= 500
1 <= Mat[i][j] <= 1000Output N*N integers in a single line separated by spaces, which are the elements of the matrix in anti-clockwise order.Sample Input
4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Sample output
1 5 9 13 14 15 16 12 8 4 3 2 6 10 11 7
Explanation:
We start from 1 , go down till 13 and then go right till 16 then go up till 4 , then we go left till 2 then down and so on in anti-clockwise fashion .
Sample Input
3
1 2 3
4 5 6
7 8 9
Sample output
1 4 7 8 9 6 3 2 5
, I have written this Solution Code: function printAntiClockWise(mat)
{
let i, k = 0, l = 0;
let m = N;
let n = N;
let cnt = 0, total = m*n;
while(k < m && l < n)
{
if (cnt == total)
break;
// Print the first column
// from the remaining columns
for (i = k; i < m; ++i)
{
process.stdout.write(mat[i][l] + " ");
cnt++;
}
l++;
if (cnt == total)
break;
// Print the last row from
// the remaining rows
for (i = l; i < n; ++i)
{
process.stdout.write(mat[m - 1][i] + " ");
cnt++;
}
m--;
if (cnt == total)
break;
// Print the last column
// from the remaining columns
if (k < m)
{
for (i = m - 1; i >= k; --i)
{
process.stdout.write(mat[i][n - 1] + " ");
cnt++;
}
n--;
}
if (cnt == total)
break;
// Print the first row
// from the remaining rows
if (l < n)
{
for (i = n - 1; i >= l; --i)
{
process.stdout.write(mat[k][i] + " ");
cnt++;
}
k++;
}
}
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given four positive integers A, B, C, and D, can a rectangle have these integers as its sides?The input consists of a single line containing four space-separated integers A, B, C and D.
<b> Constraints: </b>
1 β€ A, B, C, D β€ 1000Output "Yes" if a rectangle is possible; otherwise, "No" (without quotes).Sample Input 1:
3 4 4 3
Sample Output 1:
Yes
Sample Explanation 1:
A rectangle is possible with 3, 4, 3, and 4 as sides in clockwise order.
Sample Input 2:
3 4 3 5
Sample Output 2:
No
Sample Explanation 2:
No rectangle can be made with these side lengths., I have written this Solution Code: #include<iostream>
using namespace std;
int main(){
int a,b,c,d;
cin >> a >> b >> c >> d;
if((a==c) &&(b==d)){
cout << "Yes\n";
}else if((a==b) && (c==d)){
cout << "Yes\n";
}else if((a==d) && (b==c)){
cout << "Yes\n";
}else{
cout << "No\n";
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array A of size N. Find the smallest sum of any two numbers (on distinct indices) possible in the array,The first line of the input contains a single integer N.
The second line of the input contains N space seperated integers.
Constraints:
2 <= N <= 10<sup>5</sup>
1 <= A<sub>i</sub> <= 10<sup>9</sup>Print the smallest sum of any two numbers (on distinct indices) possible in the array,Sample Input:
5
5 3 8 7 2
Sample Output:
5, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int n;
cin >> n;
vector<int> a(n);
for(auto &i : a) cin >> i;
sort(a.begin(), a.end());
cout << a[0] + a[1];
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number X is special if X is divisible by sum of digits of X. For example 24 is special because it is divisible by 6 (2+4). You are given Q queries where in each query you are given q[i] and you have to report the q[i]th positive special number.First line of input contains Q. Next Q lines contains q[i].
Constraints :
1 <= Q <= 10000
1 <= q[i] <= 100000For each query print the q[i]th special number in a new line.Sample Input
5
1
2
10
11
12
Sample Output
1
2
10
12
18, I have written this Solution Code: import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
static void preCompute(int arr[])
{
arr[0] = 0;
int itr = 1;
for(int i=1;i<=2000000;++i){
int x=f(i);
if(i%x==0)
arr[itr++] = i;
}
}
static int f(int x)
{
int s=0;
while(x > 0)
{
s+=x%10;
x/=10;
}
return s;
}
public static void main (String[] args) {
// Your code here
int arr[] = new int[10000001];
preCompute(arr);
Scanner sc = new Scanner(System.in);
int queries = sc.nextInt();
while(queries-- > 0)
{
int n = sc.nextInt();
System.out.println(arr[n]);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number X is special if X is divisible by sum of digits of X. For example 24 is special because it is divisible by 6 (2+4). You are given Q queries where in each query you are given q[i] and you have to report the q[i]th positive special number.First line of input contains Q. Next Q lines contains q[i].
Constraints :
1 <= Q <= 10000
1 <= q[i] <= 100000For each query print the q[i]th special number in a new line.Sample Input
5
1
2
10
11
12
Sample Output
1
2
10
12
18, I have written this Solution Code: #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;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
// 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>
/////////////
int f(int x){
int s=0;
while(x)
{
s+=x%10;
x/=10;
}
return s;
}
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
vector<int> v;
v.push_back(0);
for(int i=1;i<=2000000;++i){
int x=f(i);
if(i%x==0)
v.push_back(i);
}
// cout<<v.size();
int t;
cin>>t;
while(t)
{
--t;
int n;
cin>>n;
cout<<v[n]<<"\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: Given two sorted array your task is to merge these two arrays into a single array such that the merged array is also sortedFirst line contain two integers N and M the size of arrays
Second line contains N separated integers the elements of first array
Third line contains M separated integers elements of second array
<b>Constraints:-</b>
1<=N,M<=10<sup>4</sup>
1<=arr1[], arr2[] <=10<sup>5</sup>Output the merged arraySample Input:-
3 4
1 4 7
1 3 3 9
Sample Output:-
1 1 3 3 4 7 9
, I have written this Solution Code: n1,m1=input().split()
n=int(n1)
m=int(m1)
l1=list(map(int,input().strip().split()))
l2=list(map(int,input().strip().split()))
i,j=0,0
while i<n and j<m:
if l1[i]<=l2[j]:
print(l1[i],end=" ")
i+=1
else:
print(l2[j],end=" ")
j+=1
for a in range(i,n):
print(l1[a],end=" ")
for b in range(j,m):
print(l2[b],end=" "), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two sorted array your task is to merge these two arrays into a single array such that the merged array is also sortedFirst line contain two integers N and M the size of arrays
Second line contains N separated integers the elements of first array
Third line contains M separated integers elements of second array
<b>Constraints:-</b>
1<=N,M<=10<sup>4</sup>
1<=arr1[], arr2[] <=10<sup>5</sup>Output the merged arraySample Input:-
3 4
1 4 7
1 3 3 9
Sample Output:-
1 1 3 3 4 7 9
, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define max1 10000001
int main(){
int n,m;
cin>>n>>m;
int a[n];
int b[m];
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<m;i++){
cin>>b[i];
}
int c[n+m];
int i=0,j=0,k=0;
while(i!=n && j!=m){
if(a[i]<b[j]){c[k]=a[i];k++;i++;}
else{c[k]=b[j];j++;k++;}
}
while(i!=n){
c[k]=a[i];
k++;i++;
}
while(j!=m){
c[k]=b[j];
k++;j++;
}
for(i=0;i<n+m;i++){
cout<<c[i]<<" ";
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two sorted array your task is to merge these two arrays into a single array such that the merged array is also sortedFirst line contain two integers N and M the size of arrays
Second line contains N separated integers the elements of first array
Third line contains M separated integers elements of second array
<b>Constraints:-</b>
1<=N,M<=10<sup>4</sup>
1<=arr1[], arr2[] <=10<sup>5</sup>Output the merged arraySample Input:-
3 4
1 4 7
1 3 3 9
Sample Output:-
1 1 3 3 4 7 9
, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int a[] = new int[n];
int b[] = new int[m];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
for(int i=0;i<m;i++){
b[i]=sc.nextInt();
}
int c[]=new int[n+m];
int i=0,j=0,k=0;
while(i!=n && j!=m){
if(a[i]<b[j]){c[k]=a[i];k++;i++;}
else{c[k]=b[j];j++;k++;}
}
while(i!=n){
c[k]=a[i];
k++;i++;
}
while(j!=m){
c[k]=b[j];
k++;j++;
}
for(i=0;i<n+m;i++){
System.out.print(c[i]+" ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: When learning a new language, we first learn to output some message. Here, we'll start with the famous "Hello World" message. There is no input, you just have to print "Hello World".No InputHello WorldExplanation:
Hello World is printed., I have written this Solution Code: a="Hello World"
print(a), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: When learning a new language, we first learn to output some message. Here, we'll start with the famous "Hello World" message. There is no input, you just have to print "Hello World".No InputHello WorldExplanation:
Hello World is printed., I have written this Solution Code: import java.util.*;
import java.io.*;
class Main{
public static void main(String args[]){
System.out.println("Hello World");
}
}, 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, check if it contains any negative integer.First line of input contains a single integer N. The next line contains the N space separated integers.
Constraints:-
1 < = N < = 1000
-10000 < = Arr[i] < = 10000Print "Yes" if the array contains any negative integer else print "No".Sample Input:-
4
1 2 3 -3
Sample Output:-
Yes
Sample Input:-
3
1 2 3
Sample Output:-
No, I have written this Solution Code: N = int(input())
Nums = list(map(int,input().split()))
f = False
for n in Nums:
if n < 0:
f = True
break
if (f):
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 array of N integers, check if it contains any negative integer.First line of input contains a single integer N. The next line contains the N space separated integers.
Constraints:-
1 < = N < = 1000
-10000 < = Arr[i] < = 10000Print "Yes" if the array contains any negative integer else print "No".Sample Input:-
4
1 2 3 -3
Sample Output:-
Yes
Sample Input:-
3
1 2 3
Sample Output:-
No, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a;
bool win=false;
for(int i=0;i<n;i++){
cin>>a;
if(a<0){win=true;}}
if(win){
cout<<"Yes";
}
else{
cout<<"No";
}
}
, 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, check if it contains any negative integer.First line of input contains a single integer N. The next line contains the N space separated integers.
Constraints:-
1 < = N < = 1000
-10000 < = Arr[i] < = 10000Print "Yes" if the array contains any negative integer else print "No".Sample Input:-
4
1 2 3 -3
Sample Output:-
Yes
Sample Input:-
3
1 2 3
Sample Output:-
No, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a[] = new int[n];
for(int i=0;i<n;i++){
a[i] = sc.nextInt();
}
for(int i=0;i<n;i++){
if(a[i]<0){System.out.print("Yes");return;}
}
System.out.print("No");
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Rachel got a string as a gift from Ross. She wants to exchange this string with another string of same length. A string with all the same characters is fashionable string. Find Rachel lexicographically minimum fashionable string but make sure that the new string has at least one character common with the string Ross gave her otherwise he will get upset.Input contains a single string S, denoting the string Ross gave.
Constraints:
1 <= |S| <= 10000
S contains only lowercase english letters.Print the new string Rachel gets.Sample Input
bccde
Sample Output
bbbbb
Explanation: "bbbbb" is lexicographically minimum fashionable string which has atleast one character common with the initial string.
Sample Input
a
Sample Output
a, 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().trim();
char n[] = s.toCharArray();
int posMin = 0;
for(int i=0;i<n.length;i++){
if(n[posMin]>n[i])
posMin = i;
}
for(int i=0;i<n.length;i++)
n[i] = n[posMin];
System.out.print(String.valueOf(n));
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Rachel got a string as a gift from Ross. She wants to exchange this string with another string of same length. A string with all the same characters is fashionable string. Find Rachel lexicographically minimum fashionable string but make sure that the new string has at least one character common with the string Ross gave her otherwise he will get upset.Input contains a single string S, denoting the string Ross gave.
Constraints:
1 <= |S| <= 10000
S contains only lowercase english letters.Print the new string Rachel gets.Sample Input
bccde
Sample Output
bbbbb
Explanation: "bbbbb" is lexicographically minimum fashionable string which has atleast one character common with the initial string.
Sample Input
a
Sample Output
a, 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();
//////////////
template<class C> void mini(C&a4, C b4){a4=min(a4,b4);}
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 mod 1000000007ll
#define pii pair<int,int>
/////////////
signed main(){
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
string s;
cin>>s;
char c='z';
for(auto r:s)
c=min(c,r);
for(int i=0;i<s.length();++i)
cout<<c;
#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: Rachel got a string as a gift from Ross. She wants to exchange this string with another string of same length. A string with all the same characters is fashionable string. Find Rachel lexicographically minimum fashionable string but make sure that the new string has at least one character common with the string Ross gave her otherwise he will get upset.Input contains a single string S, denoting the string Ross gave.
Constraints:
1 <= |S| <= 10000
S contains only lowercase english letters.Print the new string Rachel gets.Sample Input
bccde
Sample Output
bbbbb
Explanation: "bbbbb" is lexicographically minimum fashionable string which has atleast one character common with the initial string.
Sample Input
a
Sample Output
a, I have written this Solution Code: s=input()
l=len(s)
k=min(s)
m=k*l
print(m), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer K, find a positive integer x such that <b>K = x<sup>2</sup> + 3*x</b>. If no such positive integer x exists, print -1.First and the only line of the input contains an integer K.
Constraints:
1 <= K <= 10<sup>18</sup>Print a positive integer x such that the above equation satisfies. If no such integer x exists, print -1.Sample Input:
28
Sample Output:
4
Explaination:
4<sup>2</sup> + 3*4 = 28
There is no other positive integer that will give such result., I have written this Solution Code: def FindIt(n):
sqrt_n = int(K**0.5)
check = -1
for i in range(sqrt_n - 1, sqrt_n - 2, -1):
check = i**2 + (i * 3)
if check == n:
return i
return -1
K = int(input())
print(FindIt(K)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer K, find a positive integer x such that <b>K = x<sup>2</sup> + 3*x</b>. If no such positive integer x exists, print -1.First and the only line of the input contains an integer K.
Constraints:
1 <= K <= 10<sup>18</sup>Print a positive integer x such that the above equation satisfies. If no such integer x exists, print -1.Sample Input:
28
Sample Output:
4
Explaination:
4<sup>2</sup> + 3*4 = 28
There is no other positive integer that will give such result., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int long long
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using T = pair<int, int>;
typedef long double ld;
const int mod = 1e9 + 7;
const int INF = 1e9;
void solve(){
int n;
cin >> n;
int l = 1, r = 1e9, ans = -1;
while(l <= r){
int m = (l + r)/2;
int val = m*m + 3*m;
if(val == n){
ans = m;
break;
}
if(val < n){
l = m + 1;
}
else r = m - 1;
}
cout << ans;
}
signed main(){
fast
int t = 1;
// cin >> t;
for(int i = 1; i <= t; i++){
solve();
if(i != t) cout << endl;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer K, find a positive integer x such that <b>K = x<sup>2</sup> + 3*x</b>. If no such positive integer x exists, print -1.First and the only line of the input contains an integer K.
Constraints:
1 <= K <= 10<sup>18</sup>Print a positive integer x such that the above equation satisfies. If no such integer x exists, print -1.Sample Input:
28
Sample Output:
4
Explaination:
4<sup>2</sup> + 3*4 = 28
There is no other positive integer that will give such result., 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 K = Long.parseLong(br.readLine());
long ans = -1;
for(long x =0;((x*x)+(3*x))<=K;x++){
if(K==((x*x)+(3*x))){
ans = x;
break;
}
}
System.out.println(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a natural number N, your task is to print all the digits of the number in English words. The words have to separate by space and in lowercase English letters.<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>Print_Digit()</b> that takes integer N as a parameter.
<b>Constraints:-</b>
1 ≤ N ≤ 10<sup>7</sup>Print the digits of the number as shown in the example.
<b>Note:-</b>
Print all digits in lowercase English lettersSample Input:-
1024
Sample Output:-
one zero two four
Sample Input:-
2
Sample Output:-
two, I have written this Solution Code: def Print_Digit(n):
dc = {1: "one", 2: "two", 3: "three", 4: "four",
5: "five", 6: "six", 7: "seven", 8: "eight", 9: "nine", 0: "zero"}
final_list = []
while (n > 0):
final_list.append(dc[int(n%10)])
n = int(n / 10)
for val in final_list[::-1]:
print(val, end=' '), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a natural number N, your task is to print all the digits of the number in English words. The words have to separate by space and in lowercase English letters.<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>Print_Digit()</b> that takes integer N as a parameter.
<b>Constraints:-</b>
1 ≤ N ≤ 10<sup>7</sup>Print the digits of the number as shown in the example.
<b>Note:-</b>
Print all digits in lowercase English lettersSample Input:-
1024
Sample Output:-
one zero two four
Sample Input:-
2
Sample Output:-
two, I have written this Solution Code: class Solution {
public static void Print_Digits(int N){
if(N==0){return;}
Print_Digits(N/10);
int x=N%10;
if(x==1){System.out.print("one ");}
else if(x==2){System.out.print("two ");}
else if(x==3){System.out.print("three ");}
else if(x==4){System.out.print("four ");}
else if(x==5){System.out.print("five ");}
else if(x==6){System.out.print("six ");}
else if(x==7){System.out.print("seven ");}
else if(x==8){System.out.print("eight ");}
else if(x==9){System.out.print("nine ");}
else if(x==0){System.out.print("zero ");}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The universe contains a magic number <b>z</b>. Thor's power is known to <b>x</b> and Loki's power to be <b>y</b>.
One's strength is defined to be <b>z - a</b>, if his power is <b>a</b>. Your task is to find out who among Thor and Loki has the highest strength, and print that strength.
<b>Note:</b> The input and answer may not fit in a 32-bit integer type. In particular, if you are using C++ consider using <em>long long int</em> over <em>int</em>.The first line contains one integer t β the number of test cases.
Each test case consists of one line containing three space-separated integers x, y and z.
<b> Constraints: </b>
1 β€ t β€ 10<sup>4</sup>
1 β€ x, y β€ 10<sup>15</sup>
max(x, y) < z β€ 10<sup>15</sup>For each test case, print a single value - the largest strength among Thor and Loki.Sample Input
2
2 3 4
1 1 5
Sample Output
2
4, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
long z=0,x=0,y=0;
int choice;
Scanner in = new Scanner(System.in);
choice = in.nextInt();
String s="";
int f = 1;
while(f<=choice){
x = in.nextLong();
y = in.nextLong();
z = in.nextLong();
System.out.println((long)(Math.max((z-x),(z-y))));
f++;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The universe contains a magic number <b>z</b>. Thor's power is known to <b>x</b> and Loki's power to be <b>y</b>.
One's strength is defined to be <b>z - a</b>, if his power is <b>a</b>. Your task is to find out who among Thor and Loki has the highest strength, and print that strength.
<b>Note:</b> The input and answer may not fit in a 32-bit integer type. In particular, if you are using C++ consider using <em>long long int</em> over <em>int</em>.The first line contains one integer t β the number of test cases.
Each test case consists of one line containing three space-separated integers x, y and z.
<b> Constraints: </b>
1 β€ t β€ 10<sup>4</sup>
1 β€ x, y β€ 10<sup>15</sup>
max(x, y) < z β€ 10<sup>15</sup>For each test case, print a single value - the largest strength among Thor and Loki.Sample Input
2
2 3 4
1 1 5
Sample Output
2
4, I have written this Solution Code: n = int(input())
for i in range(n):
l = list(map(int,input().split()))
print(l[2]-min(l)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The universe contains a magic number <b>z</b>. Thor's power is known to <b>x</b> and Loki's power to be <b>y</b>.
One's strength is defined to be <b>z - a</b>, if his power is <b>a</b>. Your task is to find out who among Thor and Loki has the highest strength, and print that strength.
<b>Note:</b> The input and answer may not fit in a 32-bit integer type. In particular, if you are using C++ consider using <em>long long int</em> over <em>int</em>.The first line contains one integer t β the number of test cases.
Each test case consists of one line containing three space-separated integers x, y and z.
<b> Constraints: </b>
1 β€ t β€ 10<sup>4</sup>
1 β€ x, y β€ 10<sup>15</sup>
max(x, y) < z β€ 10<sup>15</sup>For each test case, print a single value - the largest strength among Thor and Loki.Sample Input
2
2 3 4
1 1 5
Sample Output
2
4, I have written this Solution Code: #include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
typedef long long ll;
typedef long double ld;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define reads(s) string s; cin >> s;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;}
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define setprec cout << fixed << showpoint << setprecision(20);
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const ll N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int power (int a, int b = mod - 2)
{
int res = 1;
while (b > 0) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
signed main()
{
read(t);
assert(1 <= t && t <= ll(1e4));
while (t--)
{
readc(x, y, z);
assert(1 <= x && x <= ll(1e15));
assert(1 <= y && y <= ll(1e15));
assert(max(x, y) < z && z <= ll(1e15));
int r = 2*z - x - y - 1;
int l = z - max(x, y);
print(r - l + 1);
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The universe contains a magic number <b>z</b>. Thor's power is known to <b>x</b> and Loki's power to be <b>y</b>.
One's strength is defined to be <b>z - a</b>, if his power is <b>a</b>. Your task is to find out who among Thor and Loki has the highest strength, and print that strength.
<b>Note:</b> The input and answer may not fit in a 32-bit integer type. In particular, if you are using C++ consider using <em>long long int</em> over <em>int</em>.The first line contains one integer t β the number of test cases.
Each test case consists of one line containing three space-separated integers x, y and z.
<b> Constraints: </b>
1 β€ t β€ 10<sup>4</sup>
1 β€ x, y β€ 10<sup>15</sup>
max(x, y) < z β€ 10<sup>15</sup>For each test case, print a single value - the largest strength among Thor and Loki.Sample Input
2
2 3 4
1 1 5
Sample Output
2
4, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
int t;
cin>>t;
while(t--)
{
int x, y, z;
cin>>x>>y>>z;
cout<<max(z - y, z- x)<<endl;
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cerr.tie(NULL);
#ifndef ONLINE_JUDGE
if (fopen("INPUT.txt", "r"))
{
freopen("INPUT.txt", "r", stdin);
freopen("OUTPUT.txt", "w", stdout);
}
#endif
solve();
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: def compound_interest(principle, rate, time):
Amount = principle * (pow((1 + rate / 100), time))
CI = Amount - principle
print( '%.2f'%CI)
principle,rate,time=map(int, input().split())
compound_interest(principle,rate,time), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: function calculateCI(P, R, T)
{
let interest = P * (Math.pow(1.0 + R/100.0, T) - 1);
return interest.toFixed(2);
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int p,r,t;
cin>>p>>r>>t;
double rate= (float)r/100;
double amt = (float)p*(pow(1+rate,t));
cout << fixed << setprecision(2) << (amt - p);
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.lang.Math;
class Main {
public static void main (String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] s= br.readLine().split(" ");
double[] darr = new double[s.length];
for(int i=0;i<s.length;i++){
darr[i] = Double.parseDouble(s[i]);
}
double ans = darr[0]*Math.pow(1+darr[1]/100,darr[2])-darr[0];
System.out.printf("%.2f",ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: void fizzbuzz(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){cout<<"FizzBuzz"<<" ";}
else if(i%5==0){cout<<"Buzz ";}
else if(i%3==0){cout<<"Fizz ";}
else{cout<<i<<" ";}
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int x= sc.nextInt();
fizzbuzz(x);
}
static void fizzbuzz(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){System.out.print("FizzBuzz ");}
else if(i%5==0){System.out.print("Buzz ");}
else if(i%3==0){System.out.print("Fizz ");}
else{System.out.print(i+" ");}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: def fizzbuzz(n):
for i in range (1,n+1):
if (i%3==0 and i%5==0):
print("FizzBuzz",end=' ')
elif i%3==0:
print("Fizz",end=' ')
elif i%5==0:
print("Buzz",end=' ')
else:
print(i,end=' '), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: void fizzbuzz(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){printf("FizzBuzz ");}
else if(i%5==0){printf("Buzz ");}
else if(i%3==0){printf("Fizz ");}
else{printf("%d ",i);}
}
}, 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: People prefer smartness over anything. You know N people and their smartness level. You need to place people in a circle one by one in any order. The happiness that a person gets is equal to the minimum smartness value of its clockwise neighbour and its anti-clockwise neighbour at the time when he enters the circle. You can ask the person to stand at any position of the circle that you like. The happiness of the first person to enter is 0 since he has no neighbours.
Find the maximum value of total happiness that can be achieved (sum of happiness of all the people).The first line of the input contains an integer N, the number of people you know.
The second line of the input contains N integers, the smartness of the N people that you know.
Constraints
2 <= N <= 200000
1 <= smartness of any person <= 10<sup>9</sup>Output a single integer the maximum value of total happiness.Sample Input
4
2 2 1 3
Sample Output
7
Explanation
We ask the persons to enter the circle in this particular order of smartness [3, 2, 2, 1].
Step 1:
3
Happiness attained = 0
Step 2
3
2
Happiness attained = 3
Step 3
3
2
2
Happiness attained = 2
Step 4
3
1 2
2
Happiness attained = 2
Total Happiness = 0 + 3 + 2 + 2 = 7.
Sample Input
2
1 1
Sample Output
1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws Exception {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
String s[]=(br.readLine()).split(" ");
int a[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=Integer.parseInt(s[i]);
}
Arrays.sort(a);
long sum=a[n-1];
for(int i=n-2,j=1;j<n-2;j+=2,i--)
{
sum=sum+2*a[i];
}
System.out.print(sum);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: People prefer smartness over anything. You know N people and their smartness level. You need to place people in a circle one by one in any order. The happiness that a person gets is equal to the minimum smartness value of its clockwise neighbour and its anti-clockwise neighbour at the time when he enters the circle. You can ask the person to stand at any position of the circle that you like. The happiness of the first person to enter is 0 since he has no neighbours.
Find the maximum value of total happiness that can be achieved (sum of happiness of all the people).The first line of the input contains an integer N, the number of people you know.
The second line of the input contains N integers, the smartness of the N people that you know.
Constraints
2 <= N <= 200000
1 <= smartness of any person <= 10<sup>9</sup>Output a single integer the maximum value of total happiness.Sample Input
4
2 2 1 3
Sample Output
7
Explanation
We ask the persons to enter the circle in this particular order of smartness [3, 2, 2, 1].
Step 1:
3
Happiness attained = 0
Step 2
3
2
Happiness attained = 3
Step 3
3
2
2
Happiness attained = 2
Step 4
3
1 2
2
Happiness attained = 2
Total Happiness = 0 + 3 + 2 + 2 = 7.
Sample Input
2
1 1
Sample Output
1, I have written this Solution Code: n=int(input())
lst=[int(x) for x in input().split()]
lst.sort()
m=n-1
ans=lst[n-1]
i=n-2
while(m>1):
ans+=lst[i]
ans+=lst[i]
i-=1
m-=2
print(ans), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: People prefer smartness over anything. You know N people and their smartness level. You need to place people in a circle one by one in any order. The happiness that a person gets is equal to the minimum smartness value of its clockwise neighbour and its anti-clockwise neighbour at the time when he enters the circle. You can ask the person to stand at any position of the circle that you like. The happiness of the first person to enter is 0 since he has no neighbours.
Find the maximum value of total happiness that can be achieved (sum of happiness of all the people).The first line of the input contains an integer N, the number of people you know.
The second line of the input contains N integers, the smartness of the N people that you know.
Constraints
2 <= N <= 200000
1 <= smartness of any person <= 10<sup>9</sup>Output a single integer the maximum value of total happiness.Sample Input
4
2 2 1 3
Sample Output
7
Explanation
We ask the persons to enter the circle in this particular order of smartness [3, 2, 2, 1].
Step 1:
3
Happiness attained = 0
Step 2
3
2
Happiness attained = 3
Step 3
3
2
2
Happiness attained = 2
Step 4
3
1 2
2
Happiness attained = 2
Total Happiness = 0 + 3 + 2 + 2 = 7.
Sample Input
2
1 1
Sample Output
1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(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 n; cin>>n;
vector<int> a(n);
For(i, 0, n){
cin>>a[i];
}
sort(all(a));
reverse(all(a));
int ans = 0;
ans += a[0];
int cur = 2;
For(i, 1, n){
if(cur < n){
cur++;
ans += a[i];
}
if(cur < n){
cur++;
ans += a[i];
}
}
cout<<ans;
}
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: 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.