A. 实验7_5_奇偶排序

已知n个整数,将n个整数的奇数放在前,偶数放在后,奇数部分与偶数部分都按升序排列输出。
输入与输出要求:首先输入一个整数n,代表输入整数个数,n不会超过200。然后是n个待排序的整数,每个整数的取值范围是0-1000。输出排序后的n个数,其中奇数在前偶数在后,数与数之间用空格分开,注意第n个数后没有空格而是换行符。
程序运行效果:
Sample 1:
10↙
10 9 8 7 6 5 4 3 2 1↙
1 3 5 7 9 2 4 6 8 10

#include<stdio.h>
int main()
{
	int n, a[200], b[200] = { 0 }, c[200] = { 0 }, i, j = 0, k = 0;
	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &a[i]);
	for (i = 0; i < n; i++)
	{
		if (a[i] % 2 != 0)
		{
			b[k] = a[i];
			k++;
		}
		else if (a[i] % 2 == 0)
		{
			c[j] = a[i];
			j++;
		}
	}
	//for (i = 0; i < k; i++)
		//printf("%d ", b[i]);
	//printf('\n');
	int count;
	int loc;
	for (loc = k - 1; loc >= 1; loc--)
	{
		for (count = 0; count <= loc - 1; count++)
		{
			if (b[count] > b[count + 1])
			{
				int temp1;
				temp1 = b[count];
				b[count] = b[count + 1];
				b[count + 1] = temp1;
			}
		}
	}
	for (loc = j - 1; loc >= 1; loc--)
	{
		for (count = 0; count <= loc - 1; count++)
		{
			if (c[count] > c[count + 1])
			{
				int temp1;
				temp1 = c[count];
				c[count] = c[count + 1];
				c[count + 1] = temp1;
			}
		}
	}
	for (i = 0; i < k; i++)
		printf("%d ", b[i]);
	for (i = 0; i < j; i++)
		printf("%d ", c[i]);
	printf("\n");
	return 0;
}

 

def __next_step(self, x, y): if not self.judge_colory: self.__history += 0 else: self.__history += 1 self.color = 1 if self.__history % 2 == 0 else 2 if self.start_ai_game: if self.ai_color == self.color: row,col = self.ai_stage(self.ai_game()[0],self.ai_game()[1]) else: col = round((x-self.__margin*2)/self.__cell_width) row = round((y-self.__margin*2)/self.__cell_width) stage_row = (y-self.__margin)-(self.__cell_width*row+self.__margin) stage_col = (x-self.__margin)-(self.__cell_width*col+self.__margin) if stage_col < stage_row: self.direct= 1 else: self.direct= 0 else: col = round((x - self.__margin * 2) / self.__cell_width) row = round((y - self.__margin * 2) / self.__cell_width) stage_row = (y - self.__margin) - (self.__cell_width * row + self.__margin) stage_col = (x - self.__margin) - (self.__cell_width * col + self.__margin) if stage_col < stage_row: self.direct = 1 else: self.direct= 0 if self.valide(row, col, self.direct): if self.__history % 4 == 0 or (self.__history + 2) % 4 == 0: self.__game_board.drew_turn(2) else: self.__game_board.drew_turn(1) self.add_logic(row, col, self.color) self.__game_board.draw_chess(row, col, self.color, self.direct) if self.judge_owner(row, col, self.color, self.direct): self.__game_board.drew_turn(self.judge_next(self.color)) for i in self.judge_owner(row, col, self.color, self.direct): x,y=self.draw_owner(i) self.__game_board.drew_owner(self.color, y, x) else: self.__game_board.drew_turn(self.color) self.judge_color(row, col, self.color, self.direct) print(self.logic_board_state) if 0 not in self.logic_board_owner: self.__game_board.pop_win(self.judge_winner())
最新发布
07-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值