@amitpandeykgp…how to paste code with indentation here…
I wonder how could this solution be accepted! It just prints “odd” if k equals 1, and prints “even” otherwise.
Here is my solution too short
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int t,n,k,i,s,a,p;
cin>>t;
while(t–)
{s=0;
cin>>n>>k;
for(i=0;i<n;i++)
{
cin>>a;
s+=a;
}
p=(s+1)*(long long int)pow(2,k-1);
if(p%2==0)
cout<<“even”<<endl;
else
cout<<“odd”<<endl;
}
}
Can someone point out the mistake in my solution?
I guess it’s pretty much same as @rcsldav2017 's solution.
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
int n,k,x,s=0;
cin>>n>>k;
while(n--)
{
cin>>x;
s += x%2;
}
if(k==1)
{
if(s%2)
cout<<"even"<<endl;
else
cout<<"odd"<<endl;
}
else
cout<<"even"<<endl;
return 0;
}
Number of test cases.
Your code should run for Various test case T.
You are not scanning that.
hi…
actually your logic is same as mine and
-
your logic is right too
-
what is wrong with your code
-
why u got WA?
here what you have missed…
just look at constraints
-
Constraints:
- 1 ≤ T ≤10
- 1 ≤ K ≤ pow(10,6)
- 1 ≤ N ≤ pow(10,3)
- 1 ≤ array element ≤ pow(10,9)
-Hope you get your mistake …still not…No problem
MISTAKE
-
1<=array element<pow(10,9)
- what You have done here… int n,k,x,s=0;
- ***how can u store x[1,pow(10,9)] into integer data type ***
- *** Your are thinking here is no test case …still believe look at constraints again…):P***
Solution
- *** make x and sum variable long or long long***
-*** there are multiple test cases… look at 1<=T<=10***
here is your corrected code…still did not get it …click on me
for more conversation join my group…Novice Programmers @ NITK
Happy coding
its showing runtime error…can someone please help?
#include<stdio.h>
#include<stdlib.h>
int main()
{
int t,n,k,j,i,sum=0;
scanf("%d",&t);
for(i=0;i<t;i++)
{
scanf("%d%d",&n,&k);
int *N=(int *)malloc((n+k)*sizeof(int));
for(i=0;i<n;i++)
{
scanf("%d",N+i);
sum=sum+*(N+i);
}
if(k==1)
{
if(sum%2==0)
printf("odd");
else
printf("even");
}
else
printf("even");
}
}
public static String logicHere(String fileName){
BufferedReader br = null;
int opArr[];
int N=0;
int K=0;
String line2="";
String line3="";
int initialSum=0;
String retValue="";
try {
br = new BufferedReader(new FileReader(fileName));
br.readLine();
line2=br.readLine();
line3=br.readLine();
String[] tmpCh = line2.split(" “);
N=Integer.parseInt(tmpCh[0]);
K=Integer.parseInt(tmpCh[1]);
opArr = new int[N+K];
tmpCh = line3.split(” ");
for(int i=0;i<N;i++){
int tmp=Integer.parseInt(tmpCh[i]);
opArr[i]= tmp%10;
initialSum=(initialSum + tmp)%10;
}
for(int i=N;i<K;i++){
opArr[i]=(initialSum%10)+1;
initialSum=(initialSum+opArr[i])%10;
}
if(opArr[K]%2==0)
retValue=“even”;
else
retValue=“odd”;
}
catch(Exception ex){
ex.printStackTrace();
}
return retValue;
}
Why everyone is trying to take an array and then evaluate the sum. There’s no need of it at all.
We just need to look for number of odd elements in the array. if number of odd elements is even then sum is always even.if number of odd elements is odd them sum is always odd.
enter code here
import java.util.*;
import java.math.*;
import java.util.regex.Pattern;
public class check {
// Driver code
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t>0){
int n=sc.nextInt();
int k=sc.nextInt();
int count=0;
for(int i=0;i<n;i++){
if(sc.nextInt()%2!=0){
count++;
}
}
if(count%2==0){
if(k==1)
System.out.println(“odd”);
else
System.out.println(“even”);
}else{
System.out.println("even");
}
t–;
}
}
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t–)
{
int n,k;
cin>>n>>k;
long long s=0,a[n+5];
for(int i=0;i<n;i++)
{
cin>>a[i];
s+=a[i];
}
if(k==1)
cout<<((s+1)%2?“odd”:“even”);
else if(k==2)
cout<<((2*s+1)%2?“odd”:“even”);
else
cout<<“even”;
cout<<endl;
}
return 0;
}
Plz can someone point out mistake in my code plz.Here is my code:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t–)
{
long long int n,k,i,s=0;
cin>>n>>k;
long long int a[n];
for(i=0;i<n;i++){
cin>>a[i];
if(a[i]%2==1)
s++;
}
if(s%2==1)
s=1;
else
s=0;
if(k==1)
{
if(s==1)
cout<<"odd"<<endl;
else
cout<<"even"<<endl;
}
else
cout<<"even"<<endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n,k;
cin>>n>>k;
long int a[n],s=0;
for(int i=0;i<n;i++)
{
cin>>a[i];
s+=a[i];
}
if(s%2==0&&k==1)
{
cout<<"odd\n";
}
else
cout<<"even\n";
}
return 0;
}
lol, thats his luck
IT WORKS SOME TIMES…YOUR CODE WORKS BUT U DON’T KNOW HOW IT WORK…
VERY WEAK TEST CASES…IT IS NOT GOOD AFTER SEEING VERY LOOSE TEST CASE…
This person is down voting answers to get his on top. How fascinating.
hi I have corrected your code and pointed out your mistake …hope it is helpful to u…happy coding…
nothing is short same as previous…)