编程介的小学生 2017-08-31 09:36 采纳率: 20.5%
浏览 792
已采纳

Roman Order

Roman numerals are based on seven symbols: I = 1, V = 5, X = 10, L = 50, C = 100, D = 500 and M = 1000.

Symbols are iterated to produce multiples of the decimal (1, 10, 100, 1,000) values, with V, L, D substituted for a multiple of five, and the iteration continuing: I "1", II "2", III "3", V "5", VI "6", VII "7", etc., and the same for other bases: X "10", XX "20", XXX "30", L "50", LXXX "80"; CC "200", DCC "700", etc. At the fourth iteration, a subtractive principle is employed, with the base placed before the higher base: IV for "4", IX for "9", XL for "40", XC for "90", CD for "400", CM for "900".

The basic multiples of Roman numerals thus follow a pattern:

×1 ×2 ×3 ×4 ×5 ×6 ×7 ×8 ×9
Ones I II III IV V VI VII VIII IX
Tens X XX XXX XL L LX LXX LXXX XC
Hundreds C CC CCC CD D DC DCC DCCC CM
Thousands M MM MMM

A practical way to write a Roman number is to consider the modern Arabic numeral system, and separately convert the thousands, hundreds, tens, and ones as given in the chart above. So, for instance, 1234 may be thought of as "one thousand and two hundreds and three tens and four", obtaining M (one thousand) + CC (two hundreds) + XXX (thirty) + IV (four), for MCCXXXIV. Thus eleven is XI (ten and one), 29 is XXIX (twenty and nine), and 2011 is MMXI (two thousand and ten and one). Note that the subtractive principle is not extended beyond the chart: for example, IL is not used for 49, rather this should be written as forty (XL) and nine (IX), or XLIX.

Given a list of numbers, you are to rearrange them so that if we write them as Roman numbers, they are in lexicographical order.

Input

There are multiple test cases. The first line of input is an integer T ≈ 100 indicating the number of test cases.

Each test case starts with an integer 1 ≤ n ≤ 10000. Then n numbers 0 < ai < 4000.

Output

For each test case, output the n numbers in specified order.

Sample Input

3
3
1 2 3
7
1 5 10 50 100 500 1000
11
4 5 6 7 8 9 10 11 12 13 14
Sample Output

1 2 3
100 500 1 50 1000 5 10
4 9 5 6 7 8 10 11 12 13 14

  • 写回答

1条回答

  • threenewbee 2017-09-15 15:46
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。