Daily code_1

1.调整数组使奇数全部都位于偶数前面。,
输入一个整数数组,实现一个函数,
来调整该数组中数字的顺序使得数组中所有的奇数位于数组的前半部分,
所有偶数位于数组的后半部分。

思路:
从数组首位俩边同时开始遍历,但前面遍历到偶数 则从后面找一
个奇数与其交换数值

//将数组的奇数前置

#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
void Odd_preposition(int arr[], int n)
{
	int left = 0;//数组首位下标
	int right = n - 1;//数组尾位下标
	while (left < right)
	{
		//判断是否为奇数
		if (0 == arr[left] % 2)
		{
			//从数组最后开始依次向前找奇数
			while (left < right)
			{
				if (1 == arr[right] % 2)
				{
					//交换数值
					int tmp = arr[left];
					arr[left] = arr[right];
					arr[right] = tmp;
					break;
				}
				right--;
			}
		}
		left++;
	}
}

int main()
{
	int arr[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 ,10 };
	int len = 0;
	//数组长度
	len = sizeof(arr) / sizeof(arr[0]);
	Odd_preposition(arr, len);
	for (int i = 0; i < len; i++)
	{
		printf("%d ", arr[i]);
	}
	system("pause");
	return 0;
}

//杨氏矩阵
有一个二维数组.
数组的每行从左到右是递增的,每列从上到下是递增的.
在这样的数组中查找一个数字是否存在。
时间复杂度小于O(N);
杨氏矩阵:
数组:
1 2 3
2 3 4
3 4 5
思路:
找出一个特殊的位置开始遍历数组,即四个角与中间,中间需要从四个方向考虑,过于麻烦,左上角与右下角俩边都是递增或递减,其余俩个角比较合适

//杨氏矩阵
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int find(int arr[3][3], int num)
{
	int i = 0;
	int j = 2;
	while (i < 3&&j < 3)
	{
		if (num < arr[i][j])
		{
			j--;
		}
		else if (num>arr[i][j])
		{
			i++;
		}
		else
		{
			return 1;
		}
	}
	return 0;
}
int main()
{
	int arr[3][3] = { 1, 2, 3, 2, 3, 4, 3, 4, 5 };
	int num = 0;
	scanf("%d", &num);
	int ret = find(arr, num);
	if (1 == ret)
	{
		printf("存在\n");
	}
	else
	{
		printf("不存在\n");
	}
	system("pause");
	return 0;

}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这是一个 SQL 查询语句,用于从表 temp_daily_report_amazon_abnormal_hawb 中获取一些列的数据。以下是查询中使用的每个列的说明: - `substr(a.create_time,1,10)`:将 a.create_time 字段的前10个字符作为 create_time 列的值。 - `a.tracking_id`:tracking_id 列的值。 - `a.purchase_order_number`:purchase_order_number 列的值。 - `b.code_description`:code_description 列的值,来自 dw_code_info 表。 - `c.port_code`:port_code 列的值,来自 ecms_dws.dws_hawb_base 表。 - `c.return_desc`:return_desc 列的值,来自 ecms_dws.dws_hawb_base 表。 - `case when a.kyc_flag = '1' then 'Global store' else 'Core export' end`:根据 a.kyc_flag 的值,决定 customer 列的值。 - `a.service_level`:service_level 列的值。 - `'ECMS' as 'clearance_company'`:将 clearance_company 列的值设置为字符串 'ECMS'。 - `(case when a.reason_code = '18' then concat(b.code_description,'/',ifnull(c.port_code,'')) when a.reason_code = '51' then concat(b.code_description,'/',ifnull(c.return_desc,'')) else b.code_description end )`:根据 a.reason_code 的值,决定 reason_description 列的值。如果 reason_code 是 '18',则将 b.code_description 和 c.port_code 进行拼接;如果 reason_code 是 '51',则将 b.code_description 和 c.return_desc 进行拼接;否则,reason_description 列的值为 b.code_description。 - `a.accumulated_days`:accumulated_days 列的值。 - `a.consignee_name`:consignee_name 列的值。 - `a.consignee_phone`:consignee_phone 列的值。 查询还包括以下条件: - `a.create_time = UTC_DATE()`:筛选符合当前日期(UTC)的记录。 - `(a.accumulated_days >='2' or a.accumulated_days is null)`:筛选 accumulated_days 大于等于 2 或为空的记录。 最后,结果按照 a.accumulated_days 降序和 b.priority 升序进行排序。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值