2 u013594581 u013594581 于 2014.03.04 18:02 提问

vs 编译器不让过 怎么办

void paixu(int a[],int N)
{
int temp;
int i,j;
for(i=0;i for(j=i+1;j {
if(a[i]>a[j])
{temp=a[i];a[i]=a[j];a[j]=temp;}
}
}

int rr(int input[][2])
{
int n = input[0][0];
int k = input[1][0];
int *nums = &input[0][1];

int kind[k][2];
for (int i = 1; i <= k; i++) {
    kind[i-1][0] = i;
    kind[i-1][1] = 0;
}

for (int i = 0; i < n * 2; i+=2) {
    int x = nums[i];
    for (int j = 0; j < k; j++) {
        if (x == kind[j][0]) {
            kind[j][1]++;
        }
    }
}

int unsoft[k];
int unsoft2[k];

for (int i = 1; i <= k; i++) {
    unsoft[i - 1] = kind[i-1][1] ;
    unsoft2[i - 1] = kind[i-1][1] ;
}

paixu(unsoft, k);

int s = 0;

for (int i = 0; i < k; i++) {
    if (unsoft2[i] == unsoft[k - 1])
        s = i + 1;
}

int re = n;

re = n - unsoft[k - 1];

if (re == 0) {
    return re;
}

int a = 0;
for (int i = 0; i < n * 2; i+=2) {
    int x = nums[i];
    if (x != (s + 1))
    a++;
}

return re;

}

int main(int argc, const char * argv[])
{

int n = 0;
int k = 0;

scanf("%d %d",&n, &k);

int input[n];
for (int i = 0; i < n; i++)
    scanf("%d", &input[i]);

int nums[n][2];

for (int i = 0; i < n; i++) {
    int kc = input[i];

    if (i == 0) {
        nums[i][0] = n;
    }
    if (i == 1) {
        nums[i][0] = k;
    }

    nums[i][1] = kc;
}

int a = rr(nums);
printf("%d\n", a);

return 0;

}

1个回答

cxwtc123
cxwtc123   2014.03.05 12:43

申明数组如 int int_array[size];
size 需为常量,如

int int_array[100];

如果size是变量,可定义指针,显式分配内存;

int size = 100;
int * int_array;
int_array = new int[size];

//使用完之后释放
delete[] int_array;

也可以使用容器

#include <vector>

int size = 100;
typedef vector<int> IntVector;
IntVector int_array;
int_array.resize(size);
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!