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. Angular4中路由Router类的跳转navigate

    最近一直在学习angular4,它确实比以前有了很大的变化和改进,好多地方也不是那么容易就能理解,好在官方的文档和例子是中文,对英文不太好的还是有很大帮助去学习. 官方地址:https://angul ...

  2. <jsp:param>标签给属性赋值时的一个坑

    http://blog.sina.cn/dpool/blog/s/blog_58c5066001011gdn.html 因为: <jsp:forward和<jsp:param在被编译成ja ...

  3. 手写一个selenium浏览器池

    维护一组浏览器,实现每分钟1000次查询.DriverPool使用变幻版只初始化一次的单例模式.维护每个浏览器的当前是否使用的状态. 不需要等待请求来了,临时开浏览器,开一个浏览器会耽误6秒钟. 可以 ...

  4. timer计算两个方法执行时间

    >>> from timeit import Timer >>> Timer("temp = x; x = y; y = temp", &quo ...

  5. Android学习:简易图片浏览

    这个例子学习混合使用XML布局和代码来控制UI,习惯上把变化小.行为固定的组件放在XML布局文件中管理,而那些变化较多.行为控制复杂的组件则交给Java代码来管理. 先在布局文件中定义一个线性布局容器 ...

  6. 解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)错误

    我调这个bug调了一天多,在网上搜索的检查namespace,package等,都没有错.错误提示是没有找到xml文件,我就纳闷了,为什么找不到呢?后来才发现,原来是resource中奇怪的目录为题, ...

  7. bypass safedog upload

    这里附上两个payload: Content-Disposition: form-data; name=”up_picture”; filename=”[回车]1.php” Content-Dispo ...

  8. Oracle课程档案,第一天。

    sys是Oracle最高权限者 DBSNMP:简单网络管理系统 ctrl+d回到oracle目录 在SQL中输入 exit也可以 select:列 where:行 sqlplus / as sysdb ...

  9. 最短路径spfa

    #include <stdio.h> #include <string.h> #include <algorithm> #include <queue> ...

  10. F#周报2019年第5期

    新闻 Ionide的Open Collective 发布SAFE至Google Cloud Kubernetes引擎 .NET Core 3预览2 ASP.NET Core在.NET Core 3预览 ...