新人请教一个该如何写*算法
主要原因:
目前在学习PHP的过程,想考验一下自己制作一个足球比赛单循环的赛程表出来。
算法:
*算法
把队伍排列成2行(偶数队伍),固定第一行的第一个队伍,从第一行第二个队伍开始顺时针滚动。
但我在写代码的时候怎么也写不出来(可能是我也刚接触)
我所设想的写法应该是:
3层for循环,第一层是轮次,第二层是主队,第三层是客队。
进行for echo展示赛程表。
下面代码是我自己在研究过程中写出来的,跟我要的结果完全不一样啊,不知道怎么写了,希望PHP大牛帮忙!
1 |
|
1 |
|
回复讨论(解决方案)
你这是求 7 中取 2 的组合
按求组合的通用算法即可(精华区有相关代码)
规则看不太懂 能给个结果实例要你想要的结果展示出来吗 这样别人才能更好的知道你想要的结果是什么
自己研究的话,可以这样写
1 |
|
武汉 vs 北京
武汉 vs 上海
武汉 vs 四川
武汉 vs 香港
武汉 vs 台湾
--------------------------------------------------------------------------------
广州 vs 北京
广州 vs 上海
广州 vs 四川
广州 vs 香港
广州 vs 台湾
--------------------------------------------------------------------------------
北京 vs 上海
北京 vs 四川
北京 vs 香港
北京 vs 台湾
--------------------------------------------------------------------------------
上海 vs 四川
上海 vs 香港
上海 vs 台湾
--------------------------------------------------------------------------------
四川 vs 香港
四川 vs 台湾
--------------------------------------------------------------------------------
香港 vs 台湾
--------------------------------------------------------------------------------
规则看不太懂 能给个结果实例要你想要的结果展示出来吗 这样别人才能更好的知道你想要的结果是什么
实力结果应该是
第一轮
也就是把
1234
5678
上下对阵
1523
6784
1652
7843
形成罗盘算法的运转(固定1 转动2~8)
自己研究的话,可以这样写
1 |
|
武汉 vs 北京
武汉 vs 上海
武汉 vs 四川
武汉 vs 香港
武汉 vs 台湾
--------------------------------------------------------------------------------
广州 vs 北京
广州 vs 上海
广州 vs 四川
广州 vs 香港
广州 vs 台湾
--------------------------------------------------------------------------------
北京 vs 上海
北京 vs 四川
北京 vs 香港
北京 vs 台湾
--------------------------------------------------------------------------------
上海 vs 四川
上海 vs 香港
上海 vs 台湾
--------------------------------------------------------------------------------
四川 vs 香港
四川 vs 台湾
--------------------------------------------------------------------------------
香港 vs 台湾
--------------------------------------------------------------------------------
你好,版主,你这样的写法我写过,最终生成的结果和我想要的结果是不一样的。
我所想的是
第一轮
1234
5678
第二轮
1523
6784
第三轮
1652
7843
以此类推这样的算法0.0
$arr = array(4,3,2,1,5,6,7,8);
$round = 0; //设置轮次
$arr1 = array_merge($arr, $arr);
$round %= 8;
echo $arr1[$round],$arr1[$round+1],$arr1[$round+2],$arr1[$round+3];
这个意思?
1 |
|
5678
1345
6782
1456
7823
1567
8234
1678
2345
1782
3456
1823
4567

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Alipay PHP...

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

An official introduction to the non-blocking feature of ReactPHP in-depth interpretation of ReactPHP's non-blocking feature has aroused many developers' questions: "ReactPHPisnon-blockingbydefault...
