解题思路:
注意事项:
参考代码:
#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语言程序设计教程(第三版)课后习题12.5 (C语言代码)浏览:860 |
2^k进制数 (C++代码)使用递归方法浏览:734 |
C语言程序设计教程(第三版)课后习题8.3 (Java代码)浏览:1397 |
C语言程序设计教程(第三版)课后习题9.4 (Java代码)浏览:1440 |
十->二进制转换 (C语言代码)浏览:1324 |
母牛的故事 (C语言代码)浏览:1446 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:810 |
2004年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:672 |
C语言程序设计教程(第三版)课后习题11.1 (C语言代码)浏览:515 |
时间转换 (C语言代码)浏览:685 |