|
发表于 2020-9-15 10:28:10
|
显示全部楼层
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <time.h>
using namespace std;
void PPP(int n, const int a[], int even[], int odd[]);
int eo(int n, const int a[], bool t);
void show(int n, const int a[]);
int main()
{
const int N = 23;
srand((unsigned)time(NULL));
int a[N] = {};
for (int i = 0; i < N; i++)
{
a[i] = rand() % 100;
}
int t = 0;
t = eo(N, a, true);
int *even = NULL;
even = new int[t];
t = eo(N, a, false);
int *odd = NULL;
odd = new int[t];
PPP(N, a, even, odd);
delete[] even;
even = NULL;
delete[] odd;
odd = NULL;
return 0;
}
void PPP(int n, const int a[], int even[], int odd[])
{
int f1 = 0, f2 = 0;
for (int i = 0; i < n; i++)
{
if (a[i] % 2 == 0) {
even[f1] = a[i];
f1++;
}
else {
odd[f2] = a[i];
f2++;
}
}
show(n, a);
show(f1, even);
show(f2, odd);
}
int eo(int n, const int a[], bool t)
{
int x1 = 0, x2 = 0;
for (int i = 0; i < n; i++)
{
if (a[i] % 2 == 0)
x1++;
else x2++;
}
if (t)
return x1;
return x2;
}
void show(int n, const int a[])
{
for (int i = 0; i < n; i++)
cout << setw(4) << a[i];
cout << endl;
}#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <time.h>
using namespace std;
void PPP(int n, const int a[], int even[], int odd[]);
int eo(int n, const int a[], bool t);
void show(int n, const int a[]);
int main()
{
const int N = 23;
srand((unsigned)time(NULL));
int a[N] = {};
for (int i = 0; i < N; i++)
{
a[i] = rand() % 100;
}
int t = 0;
t = eo(N, a, true);
int *even = NULL;
even = new int[t];
t = eo(N, a, false);
int *odd = NULL;
odd = new int[t];
PPP(N, a, even, odd);
delete[] even;
even = NULL;
delete[] odd;
odd = NULL;
return 0;
}
void PPP(int n, const int a[], int even[], int odd[])
{
int f1 = 0, f2 = 0;
for (int i = 0; i < n; i++)
{
if (a[i] % 2 == 0) {
even[f1] = a[i];
f1++;
}
else {
odd[f2] = a[i];
f2++;
}
}
show(n, a);
show(f1, even);
show(f2, odd);
}
int eo(int n, const int a[], bool t)
{
int x1 = 0, x2 = 0;
for (int i = 0; i < n; i++)
{
if (a[i] % 2 == 0)
x1++;
else x2++;
}
if (t)
return x1;
return x2;
}
void show(int n, const int a[])
{
for (int i = 0; i < n; i++)
cout << setw(4) << a[i];
cout << endl;
}#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <time.h>
using namespace std;
void PPP(int n, const int a[], int even[], int odd[]);
int eo(int n, const int a[], bool t);
void show(int n, const int a[]);
int main()
{
const int N = 23;
srand((unsigned)time(NULL));
int a[N] = {};
for (int i = 0; i < N; i++)
{
a[i] = rand() % 100;
}
int t = 0;
t = eo(N, a, true);
int *even = NULL;
even = new int[t];
t = eo(N, a, false);
int *odd = NULL;
odd = new int[t];
PPP(N, a, even, odd);
delete[] even;
even = NULL;
delete[] odd;
odd = NULL;
return 0;
}
void PPP(int n, const int a[], int even[], int odd[])
{
int f1 = 0, f2 = 0;
for (int i = 0; i < n; i++)
{
if (a[i] % 2 == 0) {
even[f1] = a[i];
f1++;
}
else {
odd[f2] = a[i];
f2++;
}
}
show(n, a);
show(f1, even);
show(f2, odd);
}
int eo(int n, const int a[], bool t)
{
int x1 = 0, x2 = 0;
for (int i = 0; i < n; i++)
{
if (a[i] % 2 == 0)
x1++;
else x2++;
}
if (t)
return x1;
return x2;
}
void show(int n, const int a[])
{
for (int i = 0; i < n; i++)
cout << setw(4) << a[i];
cout << endl;
} |
|