08/10/24 17:02:19
>>652
#include <stdio.h>
int main(void)
{
int P[52], Q[52];
int i, c, x;
for(i=0; i<52; i++)
P[i] = i+1;
c=0;
while(1) {
for(i=0; i<26; i++)
Q[2*i] = P[i];
for(i=26; i<52; i++)
Q[2*(i-26)+1] = P[i];
c++;
for(i=x=0; i<52; i++)
if(Q[i] != i+1)
x=1;
if(x!=0)
for(i=0; i<52; i++)
P[i] = Q[i];
else
break;
}
printf("%d times looped.\n", c);
}
本当は終了条件判断後の代入と最初の代入だとかを一緒にすべきだよな。でもここでは文意どおりに…。