1812: sort

Time Limit: 1 Sec  Memory Limit: 128 MB

Submit: 158  Solved: 30



SubmitStatusWeb 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<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define MAXN 200000
int a[MAXN],b[MAXN],c[MAXN];
int cmp(int a,int b)
{
return a>b;
}
int main()
{
int k,i=0;
char ch;
while(~scanf("%d",&a[++i]))
{
ch=getchar();
if(ch==' ') continue;
//如果两个数据之间是' '的话就继续输入,负责就开始操作
else
{
int ans=0,cnt=0;
for(int j=1;j<=i;j++)
{
if(j%2==0&&j%3!=0)
b[cnt++]=a[j];
else if(j%3==0)
c[ans++]=a[j];
}
sort(b,b+cnt);
sort(c,c+ans,cmp);
int m=0,n=0,flot=0;
for(int j=1;j<=i;j++)
{
if(flot)printf(" ");
else flot++;
if(j%2==0&&j%3!=0)
printf("%d",b[m++]);
else if(j%3==0)
printf("%d",c[n++]);
else printf("%d",a[j]);
}
printf("\n");
}
memset(a,0,sizeof(a));//数据还是清零的好,没清零错了两次
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
i=0;
}
return 0;
}

zzuli--1812--sort(模拟水题)的更多相关文章

  1. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  2. POJ 2014:Flow Layout 模拟水题

    Flow Layout Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 3091   Accepted: 2148 Descr ...

  3. zzuli 1812: sort 排序

    1812: sort Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 352  Solved: 216 SubmitStatusWeb Board De ...

  4. 模拟水题,查看二维数组是否有一列都为1(POJ2864)

    题目链接:http://poj.org/problem?id=2864 题意:参照题目 哈哈哈,这个题discuss有翻译哦.水到我不想交了. #include <cstdio> #inc ...

  5. zzulioj--1716--毒(模拟水题)

     1716: 毒 Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 96  Solved: 43 SubmitStatusWeb Board Desc ...

  6. UVA 10714 Ants 蚂蚁 贪心+模拟 水题

    题意:蚂蚁在木棍上爬,速度1cm/s,给出木棍长度和每只蚂蚁的位置,问蚂蚁全部下木棍的最长时间和最短时间. 模拟一下,发现其实灰常水的贪心... 不能直接求最大和最小的= =.只要求出每只蚂蚁都走长路 ...

  7. Codeforces 1082B Vova and Trophies 模拟,水题,坑 B

    Codeforces 1082B Vova and Trophies https://vjudge.net/problem/CodeForces-1082B 题目: Vova has won nn t ...

  8. HDU4287-STL模拟水题

    一场2012天津网络预选赛的题,签到题. 但是还是写了三四十分钟,C++和STL太不熟悉了,总是编译错误不知道怎么解决. 一开始用的Char [] 后来改成了string,STL和string搭配起来 ...

  9. hdu 4891 模拟水题

    http://acm.hdu.edu.cn/showproblem.php?pid=4891 给出一个文本,问说有多少种理解方式. 1. $$中间的,(s1+1) * (s2+1) * ...*(sn ...

随机推荐

  1. 【codeforces 367C】Sereja and the Arrangement of Numbers

    [题目链接]:http://codeforces.com/problemset/problem/367/C [题意] 我们称一个数列a[N]美丽; 当且仅当,数列中出现的每一对数字都有相邻的. 给你n ...

  2. solr启动时报错org.apache.solr.common.SolrException: undefined field text的解决办法

    solr启动时报错org.apache.solr.common.SolrException: undefined field text的解决办法 原创 2015年08月21日 20:47:40 标签: ...

  3. FPGA静态时序分析——IO口时序(Input Delay /output Delay)

    1.1  概述 在高速系统中FPGA时序约束不止包括内部时钟约束,还应包括完整的IO时序约束和时序例外约束才能实现PCB板级的时序收敛.因此,FPGA时序约束中IO口时序约束也是一个重点.只有约束正确 ...

  4. WinRar 设置默认的压缩格式为zip

    By default, WinRar uses the RAR archive format for compressing files. You may prefer using the more ...

  5. ModelForm views.py

    from django.shortcuts import render from django import forms from django.forms import fields from ap ...

  6. MVC自定义错误日志异常处理

    MVC添加错误日志处理模块很简单,只要写个继承自HandleErrorAttribute的过滤器,重新OnException方法,贴个异常处理代码如下: public class ExceptionA ...

  7. Clion远程开发

    2018.3 开始Clion可以支持远程开发了   官网教程如下: https://www.jetbrains.com/help/clion/remote-projects-support.html ...

  8. Strings are immutable

    It is tempting to use the [] operator on the left side of an assignment, with the intention of chang ...

  9. Windows 相关

    Open the Windows Update troubleshooter If your computer is having problems finding and installing op ...

  10. .net 操作INI文件

    using System.Runtime.InteropServices; using System.Text; namespace FaureciaManager { public class Fi ...