1812: sort

http://acm.zzuli.edu.cn/zzuliacm/problem.php?id=1812

用字符串输入怎么搞都搞不定

1812: sort

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 268  Solved: 51

Submit Status Web Board

Description

想必大家对排序已经很熟悉了,但是spy好像对排序不太熟悉,有一天,他看到这样一个关于排序的题目:

对于 k 个用空格分隔开的整数,依次为 n1, n2 … nk。请将所有下标不能被 3 但可以被 2 整除的数在这些数字原有的位置上进行升序排列,此外,将余下下标能被 3 整除的数在这些数字原有的位置上进行降序排列。

spy想了半天不知道怎么排序,你可以帮助他么?

Input

多组数据,每组数据一行,为k个小于1000的正整数,依次为 n1, n2 … nk。(1 <= k <= 100000)

Output

对于每组数据,输出排序后的结果。

Sample Input

1 3 4 2 10 6 8

Sample Output

1 2 6 3 10 4 8
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <map>
using namespace std;
const int SIZE=1e6+10;
int a[100010];
int b[100010],c[100010];
bool cmp(int x,int y){
    return x>y;
}
int main()
{
    int l1=1;
    while(scanf("%d",&a[l1++])!=EOF){
        int ch=getchar();
        if(ch==' ')continue;
        int l2=1,l3=1;
        for(int i=1;i<l1;i++){
            if(i%2==0&&i%3)b[l2++]=a[i];
            if(i%3==0)c[l3++]=a[i];
        }
        sort(b+1,b+l2);
        sort(c+1,c+l3,cmp);
        printf("%d",a[1]);
        for(int i=2,j=1,k=1;i<l1;i++){
            if(i%2==0&&i%3)printf(" %d",b[j++]);
            else if(i%3==0)printf(" %d",c[k++]);
            else printf(" %d",a[i]);
        }
        printf("\n");
        l1=1;
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值