2 条题解
-
019240234-唐子杰 (TZJNNU) LV 8 @ 2024-08-22 15:11:46
#include <stdio.h>
#include <stdlib.h>int main()
{
int cnt = 0;
char n[100];
gets(n);
int t = atoi(n);
int a[1000];
for (int i = 0; i < t; i++)
scanf("%d", &a[i]);
for (int i = 0; i < t; i++)
{
if (a[i] == a[i + 2])
continue;
else
cnt++;
}
printf("%d\n", cnt);
for (int i = 0; i < t; i++)
{
if (a[i] == a[i+2])
continue;
else
printf("%d ", a[i]);
}
return 0;
} -
02023-10-12 20:36:07@
#include <iostream>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
int len, nums[1000] = { 0 }, arm[1000] = { 0 };
map<int, int> mp;
cin >> len;
for (int i = 0; i < len; i++)
{
cin >> nums[i];
if (mp.find(nums[i]) != mp.end())
{
mp[nums[i]]++;
}
else
{
mp[nums[i]] = 1;
}
}
sort(nums, nums + len);
int sum = 0;
for (int i = 0; i < len; i++)
{
if (mp[nums[i]] >= 2)
{
arm[sum] = nums[i];
sum++;
arm[sum] = nums[i];
sum++;
mp[nums[i]] = 0;
}
else if (mp[nums[i]] == 1)
{
arm[sum] = nums[i];
sum++;
}}
cout << sum << endl;
for (int i = 0; i < sum; i++)
{
cout << arm[i] << " ";
}
}
- 1
信息
- ID
- 1479
- 难度
- 5
- 分类
- (无)
- 标签
- 递交数
- 115
- 已通过
- 39
- 通过率
- 34%
- 上传者