问题描述
- 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("%dn", a); return 0;
}
解决方案
申明数组如 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);
时间: 2024-10-27 15:46:27