Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.
/**Bismillahir Rahmanir Rahim.**/
#include <stdio.h>
int main()
{
long long int N, i;
scanf("%lld", &N);
long long int star[N], sheep[N];
long long int sum_trak=0, sum_sheep=0;
for(i=0; i<N; i++)
{
scanf("%lld", &sheep[i]);
star[i]=0;
}
i=0;
while(1)
{
if(i==0 && sheep[i]%2==0)
{
star[i]=1;
if(sheep[i]>0)
sheep[i]--;
break;
}
else if(i==N-1 && sheep[i]%2==1)
{
star[i]=1;
if(sheep[i]>0)
sheep[i]--;
break;
}
else if(sheep[i]%2==1)
{
sheep[i]--;
star[i]=1;
i++;
}
else if(sheep[i]%2==0)
{
star[i]=1;
if(sheep[i]>0)
sheep[i]--;
i--;
}
}
for(i=0; i<N; i++)
{
sum_sheep += sheep[i];
sum_trak += star[i];
}
printf("%lld %lld\n", sum_trak, sum_sheep);
return 0;
}
It was so helpfull...thanks a lot.may allah help you.
ReplyDelete:)
DeleteAlhamdulillah!!!
Amin!!!!
#include
ReplyDeleteint main() {
long long int n, i, sx=0, c=0;
scanf("%lld", &n);
long long int x[n], y[n];
for( i=0; i 0) x[i]--;
i += inc;
} while( i >= 0 && i < n );
for( i=0; i<n; i++ ) {
sx += x[i];
if ( x[i] != y[i] ) c++;
}
printf("%lld %lld\n", c, sx);
return 0;
}
Can you explain that?? please.....
ReplyDeleteThe program run correctly but in uri it showing 'runtime error'.
ReplyDeleteI cant find where the problem is.