九度Online Judge

OJ新增积分机制,如有任何问题或者建议,请发帖到九度论坛OJ意见反馈版,祝大家一切顺利!
亲,九度OJ官方微博开通了,欢迎你来粉!微博地址:weibo.com/jobdu

 题目1422-九度Online Judge,用代码记录你的成长之路!

题目1422:Closest Number

时间限制:10 秒

内存限制:64 兆

特殊判题:

提交:774

解决:172

题目描述:

        There is one Master In ACM_DIY called "白衣少年"(White) whose motto is "I can HOLD ANY FEMALE". Since White is really busy with HOLDING FEMALES, he has no idea of the work that is given by his boss(MALE, of course), so can you help him to solve such a simple and really easy problem: 

        Array A has N positive integers,for each A[i] (0<=i<N, indicating the i-th integer in the array A), it fits in a 32-bit signed integer ),find the closest number less than A[i] (if the distance is the same,we prefer the left one).

        If you can solve this problem, White may give you some "tips"(You know better!)

输入:

        T cases (1<=T<=5)

        For each case, the first line give an integer N(1<= N <= 10^6),then the second line has the array with N integers. (All the integers are guaranteed to fit in 32-bit signed integer)

输出:

        For each case, print one line with N space-seperated integers, where the i-th integer is the number who is less that A[i] and is closest to i if exists, otherwise it is 0. 

样例输入:
3
3
2 1 3
3
2 3 1
4
5 7 3 6
样例输出:
1 0 1
1 2 0
3 5 0 3
来源:
第四届ACM_DIY群程序设计竞赛