Robot Sort

All of the refined ingots should be sorted by size in each lot while passing by on a conveyor. Because the conveyor is already running, our robots needs to quickly swap neighboring ingots.

You are given the size and initial order of the ingots as an array of numbers. Indexes are their position, values are their sizes. You should order this array from the smallest to the largest in size.

For each action a Robot can swap two neighboring elements. Each action should be represented as a string with two digits - indexes of the swapped elements (ex, "01" - swap 0th and 1st ingots). The result should be represented as a string that contains the sequence of actions separated by commas. If the array does not require sorting, then return an empty string.

And you can swap only N*(N-1)/2 times, where N - is a quantity of ingots.

Input: An array as a tuple of integers.

Output: The sequence of actions as a string.

Example:

Precondition:

1 ≤ |array| ≤ 10

翻译:需要对一个数组进行两两排序,输出的是排序的方法

 def swap_sort(array):
a = []
array1 = list(array)
for j in range(len(array1) - 1):
for i in range(len(array1)):
if i + 1 < len(array1):
x = array1[i]
y = array1[i+1]
if x > y:
array1.insert(i+2, x)
array1.pop(i)
b = str(i)+str(i+1)
a.append(b)
c = ",".join(a)
if a == []:
return ""
else:
return c
 

How it is used:

This mission will show you how to work the simplest sorting algorithms. It also models one of the game mechanics in the classic puzzle game "Tetris Attack".

【Checkio Exercise】Robot Sort的更多相关文章

  1. 【Checkio Exercise】Probably Dice

    题目: Probably Dice Battle is full of randomnesses. You should observe randomness in a controlled sett ...

  2. 【Checkio Exercise】Three Point Circle

    计算三角形外接圆的函数: Three Point Circle If we want to build new silos, then we need to make more formal and ...

  3. 【hdu 1890】Robotic Sort

    [题目链接]:http://acm.hdu.edu.cn/showproblem.php?pid=1890 [题意] 给你n个数字; i从1到n; 每次让你把第i小的数和数组的第i个元素之间这段区间内 ...

  4. 【Codeforces 922D】Robot Vacuum Cleaner

    [链接] 我是链接,点我呀:) [题意] 让你把n个字符串重新排序,然后按顺序连接在一起 使得这个组成的字符串的"sh"子序列最多 [题解] /* * 假设A的情况好于B * 也就 ...

  5. 【39.77%】【codeforces 724B】Batch Sort

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【转帖】linux sort,uniq,cut,wc,tr,xargs命令详解

    linux sort,uniq,cut,wc,tr,xargs命令详解 http://embeddedlinux.org.cn/emb-linux/entry-level/201607/21-5550 ...

  7. 【Codeforces 340D】Bubble Sort Graph

    [链接] 我是链接,点我呀:) [题意] 让你根据冒泡排序的规则 建立一张图 问你这张图的最大独立子集的大小 [题解] 考虑a[i]会和哪些点连边? 必然是在a[i]左边且比它大的数字以及在a[i]右 ...

  8. 【BZOJ-1552&3506】robotic sort&排序机械臂 Splay

    1552: [Cerc2007]robotic sort Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 806  Solved: 329[Submit][ ...

  9. 【LeetCode OJ】Insertion Sort List

    Problem: Sort a linked list using insertion sort. The node of the linked list is defined as: /** * D ...

随机推荐

  1. 【ML入门系列】(一)训练集、测试集和验证集

    训练集.验证集和测试集这三个名词在机器学习领域极其常见,但很多人并不是特别清楚,尤其是后两个经常被人混用. 在有监督(supervise)的机器学习中,数据集常被分成2~3个,即:训练集(train ...

  2. PHP读取文本文件(TXT)

    <? header("content-type:text/html;charset=utf-8"); $file = "demo.txt"; ###判断该 ...

  3. MySQL 千万 级数据量根据(索引)优化 查询 速度

    一.索引的作用 索引通俗来讲就相当于书的目录,当我们根据条件查询的时候,没有索引,便需要全表扫描,数据量少还可以,一旦数据量超过百万甚至千万,一条查询sql执行往往需要几十秒甚至更多,5秒以上就已经让 ...

  4. Microsoft office 2019 正式版镜像下载

    http://www.xitongtiandi.net/soft_yy/4373.htmlMicrosoft office 2019 正式版镜像下载 http://www.xitongtiandi.n ...

  5. 查看java内存情况命令

    转自:http://boendev.iteye.com/blog/882479 jinfo:可以输出并修改运行时的java 进程的opts. jps:与unix上的ps类似,用来显示本地的java进程 ...

  6. NW.js 桌面应用程序

    nw.js官网    https://nwjs.io/downloads/ 中文网:https://nwjs.org.cn/ 参考文档 https://www.cnblogs.com/xuanhun/ ...

  7. 百度Aip人脸识别之python代码

    用python来做人脸识别代码量少 思路清晰, 在使用之前我们需要在我们的配置的编译器中通过pip install baidu-aip  即可 from aip import AipFace 就可以开 ...

  8. Dagger2 导入项目

    导入分为两步: 第一步: 在Project build.gradle 文件中加入: dependencies { // Dagger2 第一步classpath 'com.neenbedankt.gr ...

  9. maven的tomcat插件启动报错

    错误   :: java.lang.ClassCastException: org.springframework.web.filter.CharacterEncodingFilter cannot ...

  10. python中 requests 支持 socks代理

    参考博客 https://zhengheng.me/2016/08/25/python-requests-socks5/