Title Set basic programming monkey selected from King 7-28 (20 minutes)

Here Insert Picture Description
Solution: still by way of an array of three numbers 123 used for cycle number N, if it becomes 0 3 will, each time from the first non-zero, referred to as 1, renumbered order analogy, only when the next is not a 0, the result is also desired

#include <stdio.h>
#include <math.h>
int main()
{
    int n;
    int s[1001] = {0};
    int i;
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        s[i] = i + 1;
    }
    int count = n;
    int j = 1;
    while (count != 1)
    {
        for (i = 0; i < n; i++)
        {
            if (s[i] != 0)
            {
                s[i] = j;
                j++;
                if (j == 4)
                {
                    j = 1;
                }
                if (s[i] == 3)
                {
                    s[i] = 0;
                    count--;
                }
            }
        }
    }
    for (i = 0; i < n; i++)
    {
        if (s[i] != 0)
        {
            printf("%d", i + 1);
        }
    }
    return 0;
}
Published 287 original articles · won praise 117 · Views 8921

Guess you like

Origin blog.csdn.net/qq_44458489/article/details/105400459