I have surpassed all the test cases easily but when submitted, it shows WA. Suggestions needed
Question link - CMPRSS Problem - CodeChef
MY CODE LINK - CodeChef: Practical coding for everyone
I have surpassed all the test cases easily but when submitted, it shows WA. Suggestions needed
Question link - CMPRSS Problem - CodeChef
MY CODE LINK - CodeChef: Practical coding for everyone
Please format your code or give link to your submission
Try Tc-
n=4
1 2 3 4
It only returns 3,4
Any suggestions?
Problem is, in your for loop if condition will always run and last it will print last two indices.
I tried solving it and tried to fix it and it passed that tc but still showing WA
new solution code - CodeChef: Practical coding for everyone
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t,n,i,c=0,temp=0;
cin>>t;
while(t--)
{
cin>>n;
int arr[n];
for(i=0;i<n;i++)
{
cin>>arr[i];
}
for(i=0;i<n;i++)
{
int cnt=0,start=i;
while(i+1<n&&arr[i+1]==arr[i]+1)
{
cnt++;
i++;
}
if(i<n-1)
{
if(cnt>=2)
cout<<arr[start]<<"..."<<arr[i]<<",";
if(cnt==1)
cout<<arr[start]<<","<<arr[i]<<",";
if(cnt==0)
cout<<arr[start]<<",";
}
else
{
if(cnt>=2)
cout<<arr[start]<<"..."<<arr[i];
if(cnt==1)
cout<<arr[start]<<","<<arr[i];
if(cnt==0)
cout<<arr[start];
}
}
cout<<"\n";
}
}
thanks