好的...为了这个奇怪的任务,让我们做一些奇怪的事情(我不知道这是否可行)......实际上可能还有糟糕的编码和性能......无论如何......
现在我们有 2 个数组:名称和标记。例如,我们有 ["A", "B", "A", "A"] 用于名称和 [80,100,80,70] 用于标记。
1) Loop through names and if you do not find, say "-1", set a temp var called, say, candidate to store the person i.e. "A" at first.
2) Get the corresponding mark from marks[]
3) Replace name with the cast-ed mark => names["80", "B", "A", "A"]
4) Keep looping names and repeat the above if the name = candidate
5) At the end, you have names["80", "B", "80", "70"]
6)Loop through it and Make two temp var, say, count and target to record the first mark not equals "-1" and not containing any character i.e A-Z
7) count is used to keep the count of the target. So, target="80" and count = 2 in the 1st loop.
8) Set the element to "-1" when you have accessed it.
9) Print candidate, target and count <-- do the * thing
10) names become ["-1", "B", "-1", "70"]
11) repeat everything
12) The idea is like names[] will go like: ["A", "B", "A", "A"] => ["80", "B", "80", "70"] => ["-1", "B", "-1", "70"] => ["-1", "B", "-1", "-1"] => ["-1", "100", "-1", "-1"] => ["-1", "-1", "-1", "-1"]
我可能错过了几个步骤,但这是一个粗略的想法,我希望你能理解。最好有一个第三个数组而不是替换 names[],好吧,自己决定。总的来说,它可能需要 3-4 个嵌套循环(我无法想象这...=.=)