#2
yangfrancis2015-10-13 15:12
|
程序代码:
/*
此程序作用::::::::
把1,3,5,5,6,7(m=3,n=3)变为5,6,7,1,3,5、
*/
#include <iostream>
using namespace std;
void get(int*& a, int n) {
for(int i = 0; i < n; ++i)
cin >> a[i];
}
void Change(int *a, int n1, int *b, int n2, int* const & p) {
for(int i = 0; i < n2; ++i)*(p + i) = b[i];
for(int j = 0; j < n1; ++j)*(p + n2 + j) = a[j];
}
void print(int *a, int n) {
for(int i = 0; i < n; ++i)
cout << a[i] << " ";
}
int main() {
int m, n;
cout << "m:" ;
cin >> m;
cout << "n:";
cin >> n;
cout << "输入" << m + n << "个数:";
int *p1 = new int[m + n];
get(p1, m + n);
int *p = NULL;
Change(p1, m, p1 + m, n, p);
cout << "after:" << endl;
print(p, m + n);
}
此程序作用::::::::
把1,3,5,5,6,7(m=3,n=3)变为5,6,7,1,3,5、
*/
#include <iostream>
using namespace std;
void get(int*& a, int n) {
for(int i = 0; i < n; ++i)
cin >> a[i];
}
void Change(int *a, int n1, int *b, int n2, int* const & p) {
for(int i = 0; i < n2; ++i)*(p + i) = b[i];
for(int j = 0; j < n1; ++j)*(p + n2 + j) = a[j];
}
void print(int *a, int n) {
for(int i = 0; i < n; ++i)
cout << a[i] << " ";
}
int main() {
int m, n;
cout << "m:" ;
cin >> m;
cout << "n:";
cin >> n;
cout << "输入" << m + n << "个数:";
int *p1 = new int[m + n];
get(p1, m + n);
int *p = NULL;
Change(p1, m, p1 + m, n, p);
cout << "after:" << endl;
print(p, m + n);
}