题目描述:

源码:

#include"iostream"
#include"string"
using namespace std; void Order(int *p, int n)
{
int tmp;
if(n < 2)return;
for(int i = 0; i < n - 1; i++)
{
for(int j = 0; j < n - i - 1; j++)
{
if(p[j] > p[j + 1])
{
tmp = p[j];
p[j] = p[j + 1];
p[j + 1] = tmp;
}
}
}
} int main()
{
string str;
int nums[501], count, start, len, num;
bool ok;
while(cin>>str)
{
count = 0;
start = 0;
len = str.length();
for(int i = 0; i < len; i++)
{
if(str[i] == '5')
{
start++;
}
else
{
break;
}
}
num = 0;
ok = true;
for(int i = start; i < len; i++)
{
if(str[i] != '5')
{
ok = true;
num = num * 10 + (str[i] - '0');
}
else
{
if(ok)
{
nums[count] = num;
count++;
num = 0;
ok = false;
}
}
}
if(str[len - 1] != '5')
{
nums[count] = num;
count++;
} Order(nums, count);
for(int i = 0; i < count; i++)
{
if(i > 0)cout<<" ";
cout<<nums[i];
}
cout<<endl;
}
return 0;
}

  

HD-ACM算法专攻系列(8)——排序的更多相关文章

  1. HD-ACM算法专攻系列(21)——Wooden Sticks

    题目描述: AC源码: 此题考查贪心算法,解题思路:首先使用快速排序,以w或l按升序排序(注意相等时,应按另一值升序排序),这样就将二维变量比较,变为了一维的,排好序的一边就不需要去管了,只需要对未排 ...

  2. HD-ACM算法专攻系列(23)——Crixalis's Equipment

    题目描述: AC源码:此次考察贪心算法,解题思路:贪心的原则是使留下的空间最大,优先选择Bi与Ai差值最大的,至于为什么?这里用只有2个设备为例,(A1,B1)与(A2,B2),假设先搬运A1,搬运的 ...

  3. HD-ACM算法专攻系列(22)——Max Sum

    问题描述: AC源码: 此题考察动态规划,解题思路:遍历(但有技巧),在于当前i各之和为负数时,直接选择以第i+1个为开头,在于当前i各之和为正数时,第i个可以不用作为开头(因为前i+1个之和一定大于 ...

  4. HD-ACM算法专攻系列(20)——七夕节

    问题描述: AC源码: /**/ #include"iostream" #include"cmath" using namespace std; int mai ...

  5. HD-ACM算法专攻系列(19)——Leftmost Digit

    问题描述: AC源码: 解题关键是,数据很大,不能强算,需要使用技巧,这里使用科学计算法,令N^N=a*10^n ,取对数后变为 N*log10(N)=log10(a)+n,令x = log10(a) ...

  6. HD-ACM算法专攻系列(18)——Largest prime factor

    题目描述: 源码: 需要注意,若使用cin,cout输入输出,会超时. #include"iostream" #include"memory.h" #defin ...

  7. HD-ACM算法专攻系列(17)——find your present (2)

    题目描述: 源码: #include"iostream" #include"string" using namespace std; bool IsFirstH ...

  8. HD-ACM算法专攻系列(16)——考试排名

    问题描述: 源码: 主要要注意输出格式. #include"iostream" #include"iomanip" #include"algorith ...

  9. HD-ACM算法专攻系列(15)——Quoit Design

    问题描述: 源码: 经典问题——最近邻问题,标准解法 #include"iostream" #include"algorithm" #include" ...

随机推荐

  1. 复杂一些的SQL语句

    表连接查询得到结果集后添加数据 INSERT INTO #saleSplitProduct(saleorderID,ProductCode,ProductNum,ProductPrice, produ ...

  2. Java NIO(六)选择器

    前言 Selector选择器是Java NIO中能够检测一到多个NIO通道,并能够知晓通道是否为诸如读写事件做好准备的组件.这样使得一个单独的线程可以管理多个Channel,从而管理多个网络连接.选择 ...

  3. Spinner默认选择问题

    1.需求中使用Spinner,不允许有默认选中,在网上查了好多,有设置 spinner.setSelection(-1,true); 也有设置如下: spinner.setOnItemSelected ...

  4. .NET Datatable常用系列一

    Datatable常用系列一 一.用作集合存储数据: DataTable dt = new DataTable("action"); for (int i = 0; i < ...

  5. gcc编译c中有与lua交互的代码

    编译C程序中有与Lua有关的程序(编译环境是Linux系统,lua解释器是luajit)gcc -o test30 test30.cpp -I/usr/local/include/luajit-2.0 ...

  6. LeetCode Golang 6. Z 字形变换

    6. Z 字形变换 将一个给定字符串根据给定的行数,以从上往下.从左到右进行 Z 字形排列. 比如输入字符串为 "LEETCODEISHIRING" 行数为 3 时,排列如下: L ...

  7. servlet中地址详细分析

    path路径的写法 假设; 项目名为day01 webroot下存放静态文件demo.html 转发 request.getRequestDispatcherType("path" ...

  8. easyUI datagrid表头的合并

    图列: js代码 function initConfigTable(param){ $("#mulConfigureTableBox").empty(); $("#mul ...

  9. oracle数据库服务介绍

    共有7个服务,这七个服务的含义分别为: 1. Oracle ORCL VSS Writer Service:Oracle卷映射拷贝写入服务,VSS(Volume Shadow Copy Service ...

  10. Git学习总结(10)——git 常用命令汇总

    1.git 基本概念: 工作区:改动(增删文件和内容) 暂存区:输入命令:git add 改动的文件名,此次改动就放到了'暂存区'(新增的文件) 本地仓库(简称:本地):输入命令:git commit ...