我的代码有问题。在Xcode或使用C++11编译器中,此代码运行良好。但是,当我将此代码提交给在线法官时,判决显示“编译错误”。我认为他们使用C++4.7.1编译器,当我尝试编译它(使用 Ideone)时,它说:
prog.cpp: In function 'void printArray(int)':
prog.cpp:27: error: 'void*' is not a pointer-to-object type
prog.cpp:27: error: 'void*' is not a pointer-to-object type
prog.cpp:27: error: 'void*' is not a pointer-to-object type
prog.cpp:27: error: 'void*' is not a pointer-to-object type
prog.cpp:27: error: 'void*' is not a pointer-to-object type
prog.cpp:27: error: 'void*' is not a pointer-to-object type
prog.cpp:27: error: 'void*' is not a pointer-to-object type
prog.cpp:27: error: 'void*' is not a pointer-to-object type
prog.cpp:27: error: 'void*' is not a pointer-to-object type
prog.cpp:27: error: 'void*' is not a pointer-to-object type
prog.cpp:27: error: 'void*' is not a pointer-to-object type
prog.cpp:27: error: 'void*' is not a pointer-to-object type
void*
这是没有意义的,因为在这个程序中没有任何地方。
我不知道要改变什么。如果你们能帮我解决这个问题,那就太好了。下面是我的代码:
#include <iostream>
#include <math.h>
#include <cmath>
#include <tgmath.h>
int array[10] = {1,2,3,4,5,6,7,8,9};
int initial = 1;
int tmp;
int total[500];
using namespace std;
void swap(int x, int y){
int temp = array[x];
array[x]=array[y];
array[y]=temp;
return;
}
void printArray(int size){
int i;
for (i=0;i<size;i++){
//cout<<array[i]<<" ";
tmp= array[i];
tmp= (tmp* (pow(10.0,(size-i-1)))); // <--- Error here
total[initial]=total[initial]+ tmp;
}
initial++;
tmp=0;
//cout<<endl;
}
void permute(int k,int size){
int i;
if (k==0) printArray(size);
else{
for (i=k-1;i>=0;i--){
swap(i,k-1);
permute(k-1,size);
swap(i,k-1);
}
}
return;
}
void quickSort(int arr[], int left, int right) {
int i = left, j = right;
int tmp;
int pivot = arr[(left + right) / 2];
while (i <= j) {
while (arr[i] < pivot)
i++;
while (arr[j] > pivot)
j--;
if (i <= j) {
tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
i++;
j--;
}
};
if (left < j)
quickSort(arr, left, j);
if (i < right)
quickSort(arr, i, right);
}
int main(){
int countertest;
cin>>countertest;
int ak, asize;
for(int a= 0; a<countertest; a++){
initial = 1;
std::fill(total, total+500, 0);
cin>>asize>>ak;
permute(asize,asize);
quickSort(total, 1, initial-1);
int arraydex [10000], temp = total[ak];
for(int z = asize; z>=0; z--){
arraydex[z] = temp % 10;
temp /= 10;
}
for(int bc = 1; bc<=asize; bc++){
cout<<arraydex[bc]<<" ";
}
cout<<endl;
}
return 0;
}