You are not logged in. Please login at www.codechef.com to post your questions!

×

problems which I practise runs well on ide and gives correct on all cases that i can think.But when i try to submit them it shows wrong answer please guide me

poroblem code Voters my code is:

#include<iostream>
using namespace std;
int cmptrg(int,int,int);
int cmptrl(int,int,int);
int main()
{int n1,n2,n3;
cin>>n1>>n2>>n3;
if(n1<0||n1>50000||n2<0||n3<0||n2>50000||n3>50000)
return 0;
int l=0;
int *list1=new int[n1];
int *list2=new int[n2];
int *list3=new int[n3];
int g=cmptrg(n1,n2,n3);
int *list=new int[g];
for(int i=0;i<n1;i++)
cin>>list1[i];
for(int i=0;i<n2;i++)
cin>>list2[i];
for(int i=0;i<n3;i++)
cin>>list3[i];
int i=0,j=0,k=0;
while(i<n1&&j<n2&&k<n3)
{
int l1=list1[i];
int l2=list2[j];
int l3=list3[k];
if(l1==l2==l3)
{
list[l++]=l1;
if(i<n1-1)i++;
if(j<n2-1)j++;
if(k<n3-1)k++;
}
else
{if(l1==l2)
{list[l++]=l1;
if(i<n1-1)i++;
if(j<n2-1)j++;
}
else if(l1==l3)
{list[l++]=l1;
if(i<n1-1)i++;
if(k<n3-1)k++;
}
else if(l2==l3)
{list[l++]=l2;
if(j<n2-1)j++;
if(k<n3-1)k++;
}
int r=cmptrl(l1,l2,l3);
if (r==1)
i++;
if(r==2)
j++;
if(r==3)
k++;
}
if(i==g-1||j==g-1||k==g-1)
{
i++;j++;k++;
}
}
cout<<l<<endl;
for(int w=0;w<l;w++)
cout<<list[w]<<endl;
return 0;
}

int cmptrg(int n1,int n2,int n3)
{
if(n1>=n2)
{
if(n3>=n1)
return n3;
else
return n1;
}
else
{
if(n3>=n2)
return n3;
else
return n2;
}
}
int cmptrl(int n1,int n2,int n3)
{
    if(n1<n2)
{
if(n3<n1)
return 3;
if(n1<n3)
return 1;
}
if(n1>n2)
{
if(n3<n2)
return 3;
if(n2<n3)
return 2;
}
return 0;
}

asked 23 Jul '17, 17:34

yogi10's gravatar image

5★yogi10
52
accept rate: 0%

edited 23 Jul '17, 17:56

vijju123's gravatar image

5★vijju123 ♦
14.9k11856


Check your case for this input-

Input
2 1 1
2
1
1
2
Your Output
1
2
Expected Output
2//This is number of voters in final list
1
2
link

answered 23 Jul '17, 18:01

vijju123's gravatar image

5★vijju123 ♦
14.9k11856
accept rate: 18%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×2,583

question asked: 23 Jul '17, 17:34

question was seen: 97 times

last updated: 23 Jul '17, 18:01