WHY DO I GET WRONG ANSWER FOR COMPRESS THE LIST

THIS IS MY CODE. IT GIVES WA. HELP PLS!!

#include <bits/stdc++.h>
using namespace std;
int main()
{ ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T,N,A[100];
cin>>T;
for(int j=0;j<T;j++)
{cin>>N;
if(N==1)
{cin>>A[0];
cout<<A[0];
else
{for(int i=0;i<N;i++)
cin>>A[i];
cout<<A[0];
if(!(A[1]==A[0]+1&&A[1]==A[2]-1))
cout<<’,’;
for(int i=1;i<N-1;i++)
{
if((A[i]==A[i-1]+1&&A[i]==A[i+1]-1))
cout<<"…";
else
{cout<<A[i];
if(!(A[i+1]==A[i]+1&&A[i+1]==A[i+2]-1))
cout<<’,’;}
}
cout<<A[N-1]<<endl;
}}
return 0;
}

Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

2 Likes

This solution doesn’t even compile :slight_smile:

1 Like

it compiled on codeblocks :confused:
https://www.codechef.com/viewsolution/30341634

1 Like

Thanks - one thing that immediately leaps out is that you are printing the single character:

instead of 3 .s:

...
1 Like

is there any difference created due to that.
did it as a string of …

Codechef requires your output to be identical to the expected output (except with whitespace in certain places).

1 Like

i tried it out too! No use ig…
https://www.codechef.com/viewsolution/30342071

This prints out commas (,) instead of dots (.) :slight_smile:

1 Like

oops sorry :sweat_smile: :sweat_smile:

1 Like

again :neutral_face: :neutral_face:
https://www.codechef.com/viewsolution/30342851

Better - we’re printing out the correct characters, now :slight_smile:

This solution gives the wrong answer for the sample testcase: I recommend debugging and getting it to give the right answer for the sample testcase before submitting again :slight_smile:

1 Like

this is done using codeblocks.
also in the ques string “…” was mentioned