hdu 1106(排序)

虽然是一题水题,但还是要考虑到各种情况,不然还是A不了。

有点舒服,一次就A了,还不错。

例子:

0051231232050775
5500501235
123
55565055
0005005
100255001101

结果:

0 77 12312320
0 123
123
0 6
0 0
1002 1101

#include <iostream>
#include <string.h>
#include <string>
#include <cstdio>
#include <algorithm>
using namespace std;
char s[1005];
int a[1000];
int main(int argc, char *argv[])
{
	//freopen("D:\\c - free\\hdu_1106\\input.txt","r",stdin);
	int i,pos,cnt,flag;
	string str;
	while (gets(s) && strlen(s) != 0){
		str = "";
		cnt = 0,flag = 0,pos = 1;
		for (i = 0;i < strlen(s);i++){
			if (s[i] == '5' && pos == 1) continue;
			else if (s[i] == '5'){
				if (flag == 0) a[cnt++] = 0;
				else a[cnt++] = atoi(str.c_str());
				pos = 1;
				str = "";
			}else if (s[i] == '0' && flag == 0) pos = 0;
			else{
				str += s[i];
				pos = 0,flag = 1;
			}
		}
		if (str != "") a[cnt++] = atoi(str.c_str());
		sort(a,a+cnt);
		cout<<a[0];
		for (i = 1;i < cnt;i++) cout<<' '<<a[i];
		cout<<endl;
	}
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值