Problem Description

有n(n<=100)个整数,已经按照从小到大顺序排列好,现在另外给一个整数x,请将该数插入到序列中,并使新的序列仍然有序。

Input

输入数据包含多个测试实例,每组数据由两行组成,第一行是n和m,第二行是已经有序的n个数的数列。n和m同时为0标示输入数据的结束,本行不做处理。

Output

对于每个测试实例,输出插入新的元素后的数列。

Sample Input

3 3

1 2 4

0 0

Sample Output

1 2 3 4

/*
注意x和a[i]相等时还是要把x插入
*/ #include<stdio.h>
#include<string.h>
int main()
{
int n,x;
int k,i,flag=0;
int a[200];
while(scanf("%d %d",&n,&x)!=EOF)
{
if(n==0&&x==0) break;
for(i=1;i<=n;i++) scanf("%d",&a[i]);
if(x>=a[n])
{
for(i=1;i<=n;i++)
{
printf("%d ",a[i]);
}
printf("%d\n",x);
}
else
{
for(i=1;i<=n;i++)
{
if(x>=a[i]&&x<a[i+1]) k=i;
}
for(i=1;i<=k;i++) printf("%d ",a[i]);
printf("%d",x);
for(i=k+1;i<=n;i++) printf(" %d",a[i]);
printf("\n");
}
}
return 0;
}

HDU2019数列有序!的更多相关文章

  1. HDOJ2019数列有序!

    数列有序! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  2. hdu 2019:数列有序!(数据结构,直接插入排序+折半插入排序)

    数列有序! Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submiss ...

  3. 新疆大学OJ(ACM) 1099: 数列有序!

    1099: 数列有序! 时间限制: 1 Sec  内存限制: 128 MB 题目描述 有n(n<=100)个整数,已经按照从小到大顺序排列好,现在另外给一个整数x,请将该数插入到序列中,并使新的 ...

  4. HDU 2019 数列有序!

    Time Limit: 1000 MS Memory Limit: 32768 KB 64-bit integer IO format: %I64d , %I64u   Java class name ...

  5. HDOJ 2019 数列有序!

    #include<vector> #include<iostream> #include<algorithm> #include<cstdio> usi ...

  6. 杭电2019 数列有序!(STL解法)

    由于这题对于学过数据结构的我来说,真的是很简单,为了减少时间上的损失,链表无疑是最好的选择(因为数组要往后移位子).然后,因为最近想玩些STL的骚操作,所以就用<list>了,然后顺便学了 ...

  7. 杭电OJ第11页2010-2019道题(C语言)

    2010. 水仙花数 问题描述 Problem Description 春天是鲜花的季节,水仙花就是其中最迷人的代表,数学上有个水仙花数,他是这样定义的: "水仙花数"是指一个三位 ...

  8. HDU100题简要题解(2010~2019)

    HDU2010 水仙花数 题目链接 Problem Description 春天是鲜花的季节,水仙花就是其中最迷人的代表,数学上有个水仙花数,他是这样定义的: "水仙花数"是指一个 ...

  9. 杭电ACM2019--数列有序!

    数列有序! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

随机推荐

  1. 窗体应用程序防腾讯QQ源码

    窗体应用程序防腾讯QQ源码 using System; using System.Collections.Generic; using System.ComponentModel; using Sys ...

  2. forget suffix word aby able ability out 1

      1★ aby 2★ ability 3★ able   有`~ 能力 的,具有 这样的能力 的人或物  

  3. 【HttpClient】一个http_post请求例子

    package httpclient.httpclient; import java.io.IOException; import org.apache.http.Header; import org ...

  4. Vue + Element UI 实现权限管理系统(动态加载菜单)

    动态加载菜单 之前我们的导航树都是写死在页面里的,而实际应用中是需要从后台服务器获取菜单数据之后动态生成的. 我们在这里就用上一篇准备好的数据格式Mock出模拟数据,然后动态生成我们的导航菜单. 接口 ...

  5. vs2015 产品密钥

    一.破解秘钥 企业版    HM6NR-QXX7C-DFW2Y-8B82K-WTYJV 专业版    HMGNV-WCYXV-X7G9W-YCX63-B98R2 二.破解步骤 1.安装vs2015 2 ...

  6. linux150条命令

    ●线上查询及帮助命令(2 个)man help ●文件和目录操作命令(13 个) ls tree pwd mkdir rmdir cd touch cp mv rm ln find rename ●查 ...

  7. gitblit系列七:使用Jenkins配置自动化持续集成构建

    1.安装 方法一: 下载jenkin.exe安装文件 下载地址:https://jenkins.io/content/thank-you-downloading-windows-installer/ ...

  8. 图的关键路径,AOE,完整实现,C++描述

    body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...

  9. (Java学习笔记) Java Networking (Java 网络)

    Java Networking (Java 网络) 1. 网络通信协议 Network Communication Protocols Network Protocol is a set of rul ...

  10. [Leetcode 392]判断子序列 Is Subsequence

    [思路] 判断s是否为t的子串,所以length(s)<=length(t).于是两个指针,一次循环. 将s.t转换为数组p1.p2. i为过程中s的匹配长度. i=0空串,单独讨论返回true ...