正负分界

(还有更简单的方法,待定——明天或者以后再说吧)

#include<iostream>
using namespace std;
void div(int a[],int n)
{
	int* b1 = new int[n](), * b2 = new int[n]();
	//int b1[100] = { 0 }, b2[100] = {0};
	int i, j=0, k=0;
	for (i = 0; i < n; i++)
	{
		if (a[i] < 0)
			b1[j++] = a[i];
		else
			if (a[i] > 0)
				b2[k++] = a[i];
			else
			;
	}
	
	int* d = new int[n]();
	//int d[100] = {0};
	i = 0; j = 0;
	while (b1[j])
		d[i++] = b1[j++]; 
	j = 0;
	while (b2[j])
		d[i++] = b2[j++];
	for (i = 0; d[i]; i++)
		cout << d[i]<<"  ";
}
//  -1 -3 6 -2 7 -8 0 -4 9 10
int main()
{
	cout << "请输入一个序列,以9999作为结束标志:";
	int a[100], i = 0, n = 0;
	while (1)
	{
		cin >> a[i];
		if (a[i] == 9999)break;
		else
		{
			i++; n++;
		}
	}
	//cout << n<<endl;
	div(a, n);
	return 0;
}
#include<iostream>
#include<queue>
using namespace std;
const int Max = 100;
queue<int>q1;
queue<int>q2;
queue<int>q3;
void Print(queue<int>q)
{
	for (int i = 0; i < q.size(); i++)
	{
		int t = q.front();
		cout << t << " ";
		q.pop();
		q.push(t);
	}
}
int main()
{
	int n; cin >> n;
	int* a = new int[Max];
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (a[i] > 0)q1.push(a[i]);
		else
			if (a[i] < 0)q2.push(a[i]);
			else
				q3.push(a[i]);
	}
	//cout << q1.size();
	cout<< q3.size() << endl;
	Print(q1);
	Print(q3);
	Print(q2);
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值