Oh yep it’s correct. Thanks bro ! What a silly mistake anyways learnt something
can anyone please say what is wrong in this code please reply
#include
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t–)
{
int a[5];
int count=0;
for(int i=0;i<5;i++)
{
cin>>a[i];
}
int P;
cin>>P;
for(int i=0 ;i<5;i++)
{
a[i]=a[i]*P;
}
for(int i=0 ;i<5;i++)
{
count+=a[i];
}
if(count<=120)
{
cout<<"NO\n";
}
else
{
cout<<"YES\n";
}
}
}
why i am getting runtime NZEC error in this code
package Problems;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;
class work {
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) throws IOException {
try {
FastReader obj = new FastReader();
int testcase = obj.nextInt();
for (int i = 0; i < testcase; i++) {
int sum = 0;
int[]array = new int[5];
for (int j = 0; j < array.length; j++) {
array[j] = obj.nextInt();
}
int p = obj.nextInt();
for (int j = 0; j < array.length; j++) {
sum = sum+array[j]*p;
}
if (sum >120) {
System.out.println("Yes\n");
} else {
System.out.println("No\n");
}
}
} catch (java.lang.Throwable t) {
System.out.println(t);
}
}
}
The same error what I did during contest.Print “Yes” and “No” but your code is printing "YES and “NO”.
Whats wrong with my code?
#include <bits/stdc++.h>
#include
using namespace std;
int main() {
// your code goes here
int t;cin>>t;
while(t–)
{
int arr[5]={0};
for(int i=0;i<5;i++)
{
cin>>arr[i];
}
int p;cin>>p; int sum=0;
for(int i=0;i<5;i++)
{
arr[i]=arr[i]*p;
sum+=arr[i];
}
if(sum/24<=5)
{
cout<<"No"<<endl;
}
else
{
cout<<"Yes"<<endl;
}
}
return 0;
}
If sum is between 120 and 144. Since we are having integer division it will be 5 only, Hence , Condition in if will be true while it should be false.
why my code is showing error…very frustating …
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll t;
cin>>t;
while(t–)
{
ll a[5],i,p,sum=0;
for( i=0;i<5;i++)
{
cin>>a[i];
sum+=a[i];}
cin>>p;
if(sum*p >5*24 )
cout<<"YES\n";
else
cout<<"NO\n";
}
return 0;
}
It should be while(t–) instead of (t-)
Casesensitive
Something wrong with codechef discuss
It doesnt take the second -
I can’t figure out why I’m getting WA. Any help would be appreciated.
‘’’
#include
#include
#include
using namespace std;
int main()
{
int t, p, sum=0;
int a[5];
cin>>t;
vector<string> ans;
for(int j=0; j<t; j++)
{
for(int i=0; i<5; i++)
{
cin>>a[i];
sum=sum+a[i];
}
cin>>p;
if((sum*p)>120)
{cout<<"YES"<<"\n";}
//ans.push_back("YES");}
else
{cout<<"NO"<<"\n";
//ans.push_back("NO");}
}
}
//for(int k=0; k<t; k++)
//{cout<<ans[k]<<endl;}
return 0;
}
‘’’
Since you have declared your variable sum outside the for loop of testcases it retains the value of previous testcases. You can do two things either declare variable sum inside the for loop of testcase or after last line of code do “sum=0;”. This will reset you sum to be zero for each testcase.
Also you have to print “No” instead of “NO” and “Yes” instead of “YES”
i have written t–…but i dont know why this is showing t-
import java.util.;
import java.lang.;
import java.io.*;
/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine().trim());
for(int i=0;i<t;i++)
{
String a[]=br.readLine().trim().split(" ");
int sum=0;
for(int k=0;k<a.length-1;k++)
{
sum=sum+Integer.parseInt(a[k])Integer.parseInt(a[5]);
}
if(sum>(245))
{
System.out.println(“YES”);
}
else
{
System.out.println(“NO”);
}
}
}
}
WHEN I SUBMIT IT IS SHOWING WRONG ANSWER
PLEASE HELP WHERE IS THE MISTAKE IN CODE
The if condition should be if(sum>120) because he will have 120 hours in weekdays(24*5).
And you have to print “Yes” instead of “YES” and “No” instead of “NO”.
python solution
t = int(input())
for i in range(t):
l = []
arr = list(map(int,input().split()))
p = arr.pop()
arr = [i*p for i in arr]
new = sum(arr)
if new > 120:
print(“Yes”)
else:
print(“No”)
for _ in range(int(input())):
a = list(map(int, input().split()))
p = a[5]
if((a[0] + a[1] + a[2] + a[3] + a[4])*p > 120):
print(“Yes”)
else:
print(“No”)
^^ PYTH 3.6
Problem link: LOSTWKND Problem - CodeChef
Submit link: CodeChef: Practical coding for everyone
Solution link: CodeChef: Practical coding for everyone
Discussion link: LOSTWKND - Editorial - #39 by ritz1804
There is difference in “YES” and “Yes” and same for NO and No
yes because output is case sensitive and codechef will give WA for YES and NO in this question as i have already mentioned above