URAL 1290. Sabotage (sortings)

本文聚焦于解决一个由外星生物篡改的函数问题。通过输入数组中的正整数,函数按特定规则输出一系列数值。面对复杂的输出逻辑,文章提出优化策略并提供高效代码实现,旨在简化流程、提高运行速度。

1290. Sabotage

Time limit: 1.0 second
Memory limit: 64 MB
It is the seventh year of the terrible harmful Galaxy War... Leo Hao is one of the first defenders of his planet. He is lucky! He has gone through many troubles. For example, he stayed alive after the close combat with a meklon warrior – a perfect killing machine. He lost his left leg, right eye and spent five long months in hospital. After that incident, he had to leave the army and return to the Earth.
But Leo is lucky twice! He was able to find a good job after all these terrible incidents. Now he is a leading programmer in “U.S. Robots”. He was involved into the creation of software for zero level defense system. However, even there he was faced with interplanetary intervention! Just a few days ago it was found out that one of his co-workers is not a human! No! Physically he was a human of course, but parasitical Darloxian – agent of the most odious race in the Galaxy, captured his mind.
Obviously, mind corrupted by Darlok agent was not able to write high-quality code. That why Leo is now reviewing his code. It’s terrible!!! It is not effective, slow, dirty and tangled. It must be rewritten!
However, Leo faced trouble during the exploration of the following function: input is the array of positive integer numbers. First, function prints quantity of numbers in the array onto a sheet of paper. Then quantity of numbers in the array greater than 1 is printed. Then quantity of numbers greater than 2 and so on, until the function encounters zero (zero is never printed out). After that, special mechanical manipulator puts this sheet of paper into scanner, which reads this set of numbers into memory and the described operation repeats again. After that the new paper with numbers comes out from the printer. The scanner reads these new numbers, and stores them into the array. This array is the result of the function.
Example. Input: 4 1 6.
After first stage printer prints 3 2 2 2 1 1
After second stage the result of the function will be 6 4 1
Leo feels that it can be done more effectively. Your goal is to write a program, which will be able to replace the function written by Darlok agent, and will be much faster.

Input

First line of input contains the number N (0 ≤ N ≤ 25000). The next N lines contain integers p i (1 ≤ p i ≤ 25000) one per line. It is the input for the described function.

Output

Output should contain the result of the function, written by Darlok Agent.

Sample

inputoutput
3
4
1
6
6
4
1
Problem Author: Folklore, prepared by Den Raskovalov
Problem Source: IX Open Collegiate Programming Contest of the High School Pupils (13.03.2004)




解析:从大到小排序!!!

PS:URAL的题意总是描述的很绕,很不好懂。。。




AC代码:

#include <bits/stdc++.h>
using namespace std;

int a[25005];

int main(){
    int n;
    while(scanf("%d", &n) != EOF){
        for(int i = 0; i < n; i ++) scanf("%d", &a[i]);
        sort(a, a + n);
        for(int i = n-1; i >= 0; i --){
            printf("%d\n", a[i]);
        }
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值