HDU-1106 排序
来源:互联网 发布:真实挂机赚钱软件 编辑:程序博客网 时间:2024/06/05 23:43
排序
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 53 Accepted Submission(s) : 31
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
输入一行数字,如果我们把这行数字中的‘5’都看成空格,那么就得到一行用空格分割的若干非负整数(可能有些整数以‘0’开头,这些头部的‘0’应该被忽略掉,除非这个整数就是由若干个‘0’组成的,这时这个整数就是0)。
你的任务是:对这些分割得到的整数,依从小到大的顺序排序输出。
你的任务是:对这些分割得到的整数,依从小到大的顺序排序输出。
Input
输入包含多组测试用例,每组输入数据只有一行数字(数字之间没有空格),这行数字的长度不大于1000。
输入数据保证:分割得到的非负整数不会大于100000000;输入数据不可能全由‘5’组成。
输入数据保证:分割得到的非负整数不会大于100000000;输入数据不可能全由‘5’组成。
Output
对于每个测试用例,输出分割得到的整数排序的结果,相邻的两个整数之间用一个空格分开,每组输出占一行。
Sample Input
0051231232050775
Sample Output
0 77 12312320
Source
POJ
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int main(){<span style="white-space:pre"></span>char c[1000];<span style="white-space:pre"></span>while(scanf("%s",&c)!=EOF)<span style="white-space:pre"></span>{<span style="white-space:pre"></span>int a[1000];<span style="white-space:pre"></span>memset(a,0,sizeof(a));<span style="white-space:pre"></span>int i,k,t,l;<span style="white-space:pre"></span>l=strlen(c);<span style="white-space:pre"></span>for(i=0;;i++)<span style="white-space:pre"></span> {<span style="white-space:pre"></span> <span style="white-space:pre"></span>if(c[i]!='5') <span style="white-space:pre"></span> <span style="white-space:pre"></span> break;//用来找第一个不是5的数字<span style="white-space:pre"></span> }<span style="white-space:pre"></span> k=0;<span style="white-space:pre"></span>for(t=i;t<l;++t)<span style="white-space:pre"></span> {<span style="white-space:pre"></span> <span style="white-space:pre"></span>if(c[t]!='5')<span style="white-space:pre"></span> <span style="white-space:pre"></span> {<span style="white-space:pre"></span> <span style="white-space:pre"></span> <span style="white-space:pre"></span>for(;t<l&&c[t]!='5';++t)<span style="white-space:pre"></span> <span style="white-space:pre"></span> <span style="white-space:pre"></span>{<span style="white-space:pre"></span> <span style="white-space:pre"></span> <span style="white-space:pre"></span>a[k]=a[k]*10+c[t]-'0';<span style="white-space:pre"></span> <span style="white-space:pre"></span> <span style="white-space:pre"></span><span style="white-space:pre"></span> <span style="white-space:pre"></span> <span style="white-space:pre"></span>}<span style="white-space:pre"></span> k++;//为了下面的sort排序(如果k==0时则无法进行sort排序)<span style="white-space:pre"></span> <span style="white-space:pre"></span> }<span style="white-space:pre"></span> <span style="white-space:pre"></span> <span style="white-space:pre"></span> }<span style="white-space:pre"></span> sort(a,a+k);<span style="white-space:pre"></span> for(i=0;i<k-1;i++)<span style="white-space:pre"></span> printf("%d ",a[i]);<span style="white-space:pre"></span> printf("%d\n",a[k-1]);<span style="white-space:pre"></span>}<span style="white-space:pre"></span>return 0;}
0 0
- HDU 1106 排序
- hdu 1106排序
- hdu 1106 排序
- hdu 1106 排序
- hdu-1106 排序
- HDU-1106 排序
- HDU 1106 排序
- hdu 1106 排序
- hdu 1106 排序
- HDU 1106 排序
- HDU 1106 排序
- HDU 1106 排序
- HDU-1106排序
- hdu 1106 排序
- hdu 1106 排序
- hdu 1106 排序
- HDU 题目1106 排序
- HDU 1106 排序
- 实用中时间戳与日期互转
- uva 699 The Falling Leaves
- 看书要看好书
- HDOJ 2087 剪花布条----strstr函数
- java之反射
- HDU-1106 排序
- HDOJ 1862 EXCEL排序
- 解决安卓开发文档docs打开过慢的问题
- 用户及文件权限管理
- 泛型基础概念
- MySQL之——服务器保持与MySQL的连接
- 【leetcode】123. Best Time to Buy and Sell Stock III
- HDOJ 2014 青年歌手大奖赛_评委会打分
- [Leetcode]-Best Time to Buy and Sell Stock II