
一个农夫养了100头猪,编号1~100,隔3个号杀猪,杀完后从头再杀,问最后杀的是多少号码 5
要过程!!!!!题目:一个农夫养了100头猪,编号1~100,隔3个号杀猪,杀完后从头再杀,问最后杀的是多少号码...
要过程!!!!!题目:一个农夫养了100头猪,编号1~100,隔3个号杀猪,杀完后从头再杀,问最后杀的是多少号码
展开
2个回答
2015-06-30
展开全部
最后肯定是剩1、2、3号,再排,再杀1号,再杀3号,最后杀2号
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
刚刚回答错了 应该是91 用递归算法
public class Count3 {
public static void main(String[] args) {
int[] a = new int[100];
for(int i=0; i<a.length; i++) {
a[i] = 1;
}
int leftCount = 100;
int countNum = 0;
int index = 1;
while(leftCount != 0) {
if(a[index-1] == 1) {
countNum ++;
if(countNum ==3) {
System.out.print(index + " ");
countNum = 0;
a[index-1] = 0;
leftCount --;
}
}
index ++;
if(index-1 == a.length) {
index = 1;
}
}
}
}以上是过程
public class Count3 {
public static void main(String[] args) {
int[] a = new int[100];
for(int i=0; i<a.length; i++) {
a[i] = 1;
}
int leftCount = 100;
int countNum = 0;
int index = 1;
while(leftCount != 0) {
if(a[index-1] == 1) {
countNum ++;
if(countNum ==3) {
System.out.print(index + " ");
countNum = 0;
a[index-1] = 0;
leftCount --;
}
}
index ++;
if(index-1 == a.length) {
index = 1;
}
}
}
}以上是过程
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询