小编Lor*_*chi的帖子

C语言中的Fisher Yates改组算法

我被要求分配一个在数组上使用FisherYates shuffle的功能,以便使用函数从文件中提取(我设法做到)。

 int FisherYates(int *player, int n) { //implementation of Fisher                 
     int i, j, tmp; // create local variables to hold values for shuffle

     for (i = n - 1; i > 0; i--) { // for loop to shuffle
         j = rand(); //randomise j for shuffle with Fisher Yates
         tmp = player[j];
         player[j] = player[i];
         player[i] = tmp;
     }
     return player;
}
Run Code Online (Sandbox Code Playgroud)

从根本上讲,它只需要洗牌手列表,然后将输出返回给我,这样我就可以在main()中将其打印出来。

如果有人可以向我展示如何修改代码以使其正常工作,我将不胜感激,因为使用此版本,在编译时会出现错误:

 invalid conversion from 'int*' to 'int' [-fpermissive]
Run Code Online (Sandbox Code Playgroud)

c

1
推荐指数
1
解决办法
4008
查看次数

Python FizzBu​​zz

我已经在Python中提出了这个问题:

从用户处获取一个数字列表,然后在该列表中运行FizzBu​​zz.

循环浏览列表时,请记住以下规则:

1)如果数字可以被3和5打印整除 FizzBuzz

2)如果它只能被3个打印整除 Fizz

3)如果它只能被5个打印整除 Buzz

4)否则只需打印数字

还记得elif!

我创建了以下脚本,但它在if上给出了一个错误 n%3=True

n=input()
    if n%3=True:
        print("Fizz")
    else if n%5=True:
        print ("Buzz")
    elif print n
Run Code Online (Sandbox Code Playgroud)

有人可以帮忙吗?非常感谢你!

python fizzbuzz python-2.7

-6
推荐指数
2
解决办法
5127
查看次数

标签 统计

c ×1

fizzbuzz ×1

python ×1

python-2.7 ×1