第11课。

This commit is contained in:
unlockable
2022-12-01 15:41:10 +08:00
parent a37a95fbed
commit 42158dfdef
4 changed files with 191 additions and 0 deletions

32
11/Exercise2.c Normal file
View File

@@ -0,0 +1,32 @@
#include <stdio.h>
#include <stdbool.h>
#define INCIRCLE false
#define OUTCIRCLE true
void del(int *p, int m) {
int nowPos = 0, count = 0, outCount = 0;
for (outCount = 0; outCount < m - 1; outCount++) {
count = 0;
while (count < 3) {
if ( *(p + nowPos) == INCIRCLE) {
count++;
}
nowPos = (nowPos + 1) % m;
}
*(p + ((nowPos + m - 1) % m)) = OUTCIRCLE;
}
for (;;nowPos = (nowPos + 1) % m) {
if (*(p+nowPos) == INCIRCLE) {
printf("%d\n", nowPos + 1);
break;
}
}
}
int main() {
int num[50] = {0};
int n = 0;
scanf("%d", &n);
del(num, n);
return 0;
}