6 条题解
-
0Infinity_ LV 8 @ 2024-08-23 18:13:01
#include<bits/stdc++.h> #define x INT_MIN using namespace std; int a[10010], b[10010]; int main(){ ios::sync_with_stdio(false); int n, m; cin >> n >> m; a[0] = x; a[n+1] = x; b[0] = x; b[m+1] = x; for(int i = 1; i <= n; i++)cin >> a[i]; for(int i = 1; i <= m; i++)cin >> b[i]; for(int i = 1; i <= n; i++){ if(a[i] > a[i+1])cout << a[i] << ' '; } cout << endl; for(int i = 1; i <= m; i++){ if(b[i] > b[i+1])cout << b[i] << ' '; } return 0; }
-
02022-10-09 10:19:44@
#include<stdio.h>
int main()
{
int m, n;
int a = 0;
int b = 0;
int x = 0;
int y = 0;
int arr1[10000];
int arr2[10000];
int ch1[10000];
int ch2[10000];
scanf("%d%d", &m, &n);
for (int i = 0; i < m; i++)
{
scanf("%d", &arr1[i]);
}
for (int j = 0; j < n; j++)
{
scanf("%d", &arr2[j]);
}
while (x < m)
{
if (x == 0 && arr1[x] > arr1[x + 1])
{
ch1[a] = arr1[0];
a++;
}
if (x != 0)
{
if (x != m - 1)
{
if (arr1[x] > arr1[x - 1] && arr1[x] > arr1[x + 1])
{
ch1[a] = arr1[x];
a++;
}
}
else
ch1[a] = arr1[m - 1];
}
x++;
}
while (y < n)
{
if (y == 0 && arr2[y] > arr2[y + 1])
{
ch2[b] = arr2[0];
b++;
}
if (y != 0)
{
if (y != n - 1)
{
if (arr2[y] > arr2[y - 1] && arr2[y] > arr2[y + 1])
{
ch2[b] = arr2[y];
b++;
}
}
else
ch2[b] = arr2[n - 1];
}
y++;
}
for (int s = 0; s < a + 1; s++)
{
printf("%d ", ch1[s]);
}
printf("\n");
for (int t = 0; t < b + 1; t++)
{
printf("%d ", ch2[t]);
}
return 0;
} -
02022-10-08 15:16:02@
#include <stdio.h>
//C语言好像只能拿指针做啊。。好麻烦
int min(int m[],int len,int*p);
int min2(int m[],int len);
int main(){
int n1,n2;
scanf("%d%d",&n1,&n2);
int a[n1];
int b[n2];
for(int i=0;i<n1;i++){
scanf("%d",&a[i]);
}
for(int i=0;i<n2;i++){
scanf("%d",&b[i]);
}
int h1[min2(a,sizeof(a)/sizeof(a[0]))];
int h2[min2(b,sizeof(b)/sizeof(b[0]))];
min(a,sizeof(a)/sizeof(a[0]),h1);
min(b,sizeof(b)/sizeof(b[0]),h2);
for(int i=0;i<sizeof(h1)/sizeof(h1[0]);i++){
printf("%d ",h1[i]);
}
printf("\n");
for(int i=0;i<sizeof(h2)/sizeof(h2[0]);i++){
printf("%d ",h2[i]);
}
return 0;
}
int min2(int m[],int len){
int cnt=1;
for(int i=0;i<len-1;i++){
if(m[i+1]<m[i])
cnt++;
}
return cnt;
}
int min(int m[],int len,int*p){
int x=0;
for(int i=0;i<len-1;i++){
if(m[i+1]<m[i])
{
p[x]=m[i];
x++;
}
}
p[x]=m[len-1];
return *p;
}
//法2 有点暴力求解的意思。。。但雀氏简单
#include <stdio.h>
int main(){
int n1,n2;
scanf("%d%d",&n1,&n2);
int a[n1];
int b[n2];
for(int i=0;i<n1;i++){
scanf("%d",&a[i]);
}
for(int i=0;i<n2;i++){
scanf("%d",&b[i]);
}
for(int i=0;i<(n1-1);i++){
if(a[i+1]<a[i])
printf("%d ",a[i]);
}
printf("%d",a[n1-1]);
printf("\n");
for(int i=0;i<(n2-1);i++){
if(b[i+1]<b[i])
printf("%d ",b[i]);
}
printf("%d",b[n2-1]);
return 0;
} -
02021-03-19 21:32:52@
#include<iostream> #include<cstring> using namespace std; class jidazhi{ public: void input(int a[],int na){ for(int i=0;i<na;i++) cin>>a[i]; } void jdz(int a[],int na){ for(int i=0;i<na-1;i++) if(a[i]>a[i+1]) cout<<a[i]<<" "; cout<<a[na-1]; } private: }k; int main(){ int na,nb;cin>>na>>nb; int a[na],b[nb]; k.input(a,na); k.input(b,nb); k.jdz(a,na); printf("\n"); k.jdz(b,nb); return 0; }
-
02021-03-13 11:51:24@
#include <iostream>
using namespace std;int main()
{
int n1,n2;
cin>>n1>>n2;
int a[10001],b[10001];
for(int i=0;i<n1;i++)
cin>>a[i];
for(int i=0;i<n2;i++)
cin>>b[i];
long long tmp=-10000;
for(int i=0;i<n1;i++)
{
if(a[i]<tmp)
cout<<tmp<<" ";
tmp=a[i];
}
cout<<a[n1-1]<<endl;
tmp=-10000;
for(int i=0;i<n2;i++)
{
if(b[i]<tmp)
cout<<tmp<<" ";
tmp=b[i];
}
cout<<b[n2-1]<<endl;
}
// 5 6
//1 2 3 1 2
//2 1 3 5 7 1 -
-12021-03-10 16:35:59@
#include <iostream>
using namespace std;
int main()
{
int n;
cin>>n;
int a[n];
int m;
cin>>m;
int b[m];
for(int i=0;i<n;i++)
cin>>a[i];
for(int i=0;i<m;i++)
cin>>b[i];
///////////////////////
if(a[0]>a[1])
cout<<a[0]<<" ";
for(int y=1;y<n-1;y++)
{
if((a[y]>a[y+1])&&(a[y]>a[y-1]))
cout<<a[y]<<" ";
}
cout<<a[n-1]<<endl;
//////////////if(b[0]>b[1])
cout<<b[0]<<" ";
for(int y=1;y<m-1;y++)
{
if((b[y]>b[y+1])&&(b[y]>b[y-1]))
cout<<b[y]<<" ";
}
cout<<b[m-1]<<endl;
return 0;
}
- 1
信息
- 难度
- 7
- 分类
- (无)
- 标签
- 递交数
- 1467
- 已通过
- 266
- 通过率
- 18%
- 被复制
- 11
- 上传者