题解 | #数组元素处理#
数组元素处理
http://www.nowcoder.com/practice/bb840c11be674d01b582847a6921d384
using namespace std;
void func(int* p, int n);
int main() {
int arr[6] = { 0 };
for (int i = 0; i < 6; i++) {
cin >> arr[i];
}
func(arr, 6);
for (int i = 0; i < 6; i++) {
if (i == 5) {
cout << arr[i] << endl;
}
else {
cout << arr[i] << " ";
}
}
return 0;
}
void func(int* p, int n) {
int i,j;
int result[6]={0};
j=0;
for(i=0;i<=5;i+=1){
if(p[i]!=0){
result[j]=p[i];
j+=1;
}
}
for(i=0;i<=5;i+=1){
if(p[i]==0){
result[j]=p[i];
j+=1;
}
}
for(i=0;i<=5;i+=1){
p[i]=result[i];
}
// write your code here......
}