解题思路:
注意事项:
参考代码:
#include<stdio.h>
int main() {
int n,m;
while(scanf("%d %d",&n,&m)!=EOF) {
int s=0;
for(int i=2; i<=n; i++) {
s=(s+m)%i;
}
printf("%d\n",s+1);
}
return 0;
}
-------------------------------------------------------------------------------------------------------------
int main() {
int n,m;
int table[200];
int baoShu;
int index;
int count;
while(scanf("%d %d",&n,&m)!=EOF) {
count=n;
baoShu=0;
index=0;
for(int i=1; i<=n; i++) {
table[i]=1;
}
while(count>1) {
index++;
baoShu++;
if(index>n) {
index=1;
}
while(table[index]==0) {
index++;
if(index>n)
index=1;
}
if(baoShu==m) {
table[index]=0;
baoShu=0;
count--;
}
}
for(int i=1; i<=n; i++) {
if(table[i]==1)
printf("%d\n",i);
}
}
return 0;
}
0.0分
1 人评分
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:1530 |
WU-链表数据求和操作 (C++代码)浏览:1331 |
C语言程序设计教程(第三版)课后习题5.8 (C语言代码)浏览:675 |
C语言程序设计教程(第三版)课后习题10.3 (C语言代码)浏览:551 |
【绝对值排序】 (C语言代码)浏览:867 |
C语言考试练习题_一元二次方程 (C语言代码)浏览:592 |
Hello, world! (C语言代码)浏览:725 |
【偶数求和】 (C语言代码)浏览:444 |
循环入门练习6 (C语言代码)浏览:989 |
【计算直线的交点数】 (C语言代码)浏览:930 |