int main(void) {
int no, flimit, i, pos_of_fval, freq_of_fval, n, j;
long long int max;
scanf("%d %d", &n, &flimit);
char list[n][21];
long long int fval[n];
char disp[flimit][21];
for (i = 0; i < n; i++)
scanf("%s %lld", list[i], &fval[i]);
for (i = 0; i < flimit; i++) {
max = 0;
for (j = 0; j < n; j++)
if (fval[j] > max) {
max = fval[j];
pos_of_fval = j;
}
freq_of_fval = freq(fval, max, n);
if (freq_of_fval == 1) {
strcpy(disp[i], list[pos_of_fval]);
fval[pos_of_fval] = 0;
} else
lexical(list, disp, fval, i, n, freq_of_fval, max);
}
for (i = 0; i < flimit; i++)
printf("%s\n", disp[i]);
return 0;
}
int freq(long long fval[], long long max, int n) {
int count = 0, i;
for (i = 0; i < n; i++)
if (fval[i] == max)
count++;
return count;
}
void lexical(char list[][21], char disp[][21], long long fval[],
intn dispos ,intn, int freq_of_fval, long long max) {
int a[freq_of_fval], i, j, apos = 0, temp;
for (j = 0; j < freq_of_fval; j++) {
for (i = 0; i < n; i++)
if (fval[i] == max)
a[apos++] = i;
}
for (i = 0; i < freq_of_fval - 1; i++) {
for (j = 0; j < freq_of_fval - 1 - i; j++) {
if (strcmp((list[a[j]]), list[a[j + 1]]) > 1) {
temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}
strcpy(disp[dispos], list[a[0]]);
}
錯誤:如何通過任何類型的二維數組
warning: passing argument 1 of 'lexical' from incompatible pointer type
lexical(list,disp,fval,i,n,freq_of_fval,max);
note: expected 'char \*' but argument is of type 'char (\*)[21]'
void lexical(char list[],char disp[][21],long long fval[], int dispos, int
首先歡迎您的StackOverflow!第二,你應該提供[mcve] ...第三隻是拋出代碼和錯誤不被認爲是一個好問題:) – geisterfurz007
* void lexical(char list [] [21],char disp [] [21] ,long long fval [],*'intn' * dispos,*'intn' *,int freq_of_fval,long long max)* - 真的嗎? –