### Benbircoderim1_'s blog

By Benbircoderim1_, history, 7 weeks ago,

My code for "Magnets" problem works on gcc version 6.1 but codeforces uses gcc 5.1. Is it version related runtime error.

/*
Magnets:

Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead.

Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other
and the opposite poles will attract each other.

Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row.
Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together)
or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.

*/

#include <stdio.h>
#define SIZE 100000L

void TakeMagSize(long *a)
{
scanf("%ld",a);
}

void StoreMagnetType(long *a, long b)
{
for (long i = 0; i < b; i++)
{
scanf("%ld",&a[i]);
}
}

void calc(long *a, long b)
{
int groupcounter=0;
int temp=0;

for (long i = 0; i < b; i++)
{
if(temp!=a[i])    groupcounter++;
temp=a[i];
}

printf("%d",groupcounter);
}
int main(void)
{
long mag;
long magnets[SIZE];
long counter;
TakeMagSize(&mag);
StoreMagnetType(magnets,mag);
calc(magnets, mag);

return 1;
}


• 0

 » 7 weeks ago, # | ← Rev. 2 →   0 Try to submit it with changing return 1 to "return 0;". It is not about gcc version