第四届吉林省大学生程序设计大赛个人解题报告 Problem H: New Feature in Windows 7

               Problem H: New Feature in Windows 7

Windows 7 is one version of Microsoft Windows Family; a series of operating systems produced by Microsoft running on personal computers, including home and business desktops, laptops, notebooks, tablet PCs, and media center PCs. Windows 7 was released to manufacturing on July 22, 2009, and reached general retail availability on October 22, 2009. Windows 7 studies and includes some features from some other successful operating systems, such as Mac OS and Linux. It is said that Windows 7 is more user-friendly than its predecessors especially than Vista, using which you may be forced to click “OK” four times just for copying files. For example, you can find something more interesting when sorting files. Of course, files will be sorted by their names in alphabetical order in some version of previous Windows. However, it may bring unexpected results. Suppose that there are some files named as “Lesson1”, “Lesson2”, …, “Lesson9”, ”Lesson10” and “Lesson11”, in which the numbers describe the sequence of lessons. Then, in previous version the numbers in filenames are ranked by alphabetical place and the sorted results are “Lesson1”, ”Lesson10”, “Lesson11”, “Lesson2”, …“Lesson9”. Obviously, it is not what you want, because the numbers should be ranked by their values. Now, Windows 7 realizes this. Now your task is to sort these filenames from small to large like Windows7. Exactly speaking, if two filenames are same before certain position including start, the order should be decided by these conditions:

a) If both of them are alphabets, the result depends on the alphabet order.
b) If one is alphabet and the other is number, the number is smaller.
c) If both of them are numbers, the result depends on number values.

To simplify the problem, firstly, only filenames excluding extensions are given. Secondly, only alphabets ‘A’-‘Z’, ‘a’-‘z’, digits ‘0’-‘9’ are used in filenames. Finally, there is no such number whose first digit is ‘0’.  

Input
The first line of each case is an integer n (2<=n<=100), which is the number of
the following filenames. The end of input is indicated by n=0.
There is only one filename in each following lines. The length of filename is no
more than 100 characters.

Output
For each case, sort these filenames according to the above rules. Print the results on every line. Output a blank line after each case.

Sample Input
3
Lesson11
Lesson2
Lesson1
5
A101b
A1
B1
A2a
A99b
0

Sample Output
Lesson1
Lesson2
Lesson11
 
A1
A2a
A99b
A101b
B1 

 

    这是本次比赛最让人纠结的模拟题,主要让人纠结的是当时这道题的数据是错的...所以很多人都栽到了这道题之上。我也是其中之一。

    知道模拟题主要模拟的是Win7的文件排序,可以在 a1 a2 a10 a11 a3 这样的字符串序列排成 a1 a2 a3 a10 a11。如果用原始的字符串比较的话,会出现 a1 a10 a11 a2 a3这样的结果。其他的细节都在题目中,那些细节很显然,就是这个数字数字的比较,有可能数字很大,所以比较需要逐位比较。

下面贴出我为验证正确性的代码(比赛时候敲的那份被孔哥删了...)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值