代码拉取完成,页面将自动刷新
#define _CRT_SECURE_NO_WARNINGS 1
//BC122 有序序列判断
#include <stdio.h>
#include <stdlib.h>
int cmp(const void* s1, const void* s2)
{
return (-(*(int*)s1 - *(int*)s2));
}
int main()
{
int n = 0;
int m = 0;
int i = 0;
int count1 = 0;
int count = 0;
int arr1[50] = { 0 };
int arr2[50] = { 0 };
scanf("%d", &n);
int k = n;
while (k--)
{
scanf("%d", &m);
arr1[i] = m;
arr2[i] = m;
i++;
}
qsort(arr1, 50, sizeof(arr1[0]), cmp);
for (int i = 0; i < n; i++)
{
if (arr1[i] != arr2[n-i-1])
{
count++;
break;
}
}
for (int i = 0; i < n; i++)
{
if (arr1[i] != arr2[i])
{
count1++;
break;
}
}
if (count == 0 || count1 == 0)
printf("sorted");
else
printf("unsorted");
return 0;
}
//BC123 有序序列插入一个整数
#include <stdio.h>
int main()
{
int n = 0;
int i = 0;
int m = 0;
int s = 0;
int count = 0;
int arr[51] = { 0 };
scanf("%d", &n);
int k = n;
while (k--)
{
scanf("%d", &m);
arr[i] = m;
i++;
}
scanf("%d", &s);
if (arr[0] > s)
{
int tmp = arr[0];
arr[0] = s;
s = tmp;
}
for (int j = 0; j < n; j++)
{
if ((s > arr[j] && s < arr[j + 1]) || arr[j + 1] == 0)
{
int tmp = arr[j + 1];
arr[j + 1] = s;
s = tmp;
}
}
for (int i = 0; i < n + 1; i++)
printf("%d ", arr[i]);
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。