Compile Error
foo.c: In function 'solve': foo.c:7:28: error: variable-sized object may not be initialized except with an empty initializer 7 | int frequency[M][26] = {0}; | ^
Code
#include <stdio.h>
#include <string.h>
void solve() {
int N, M;
scanf("%d %d", &N, &M);
char T[N][M + 1];
int frequency[M][26] = {0};
for (int i = 0; i < N; i++){
scanf("%s", T[i]);
for (int j = 0; j < M; j++){
frequency[j][T[i][j] - 'a']++;
}
}
char S[M + 1];
for (int j = 0; j < M; j++){
int max_freq = 0, best_char = 'a';
for (int c = 0; c < 26; c++){
if (frequency[j][c] > max_freq){
max_freq = frequency[j][c];
best_char = 'a' + c;
}
}
S[j] = best_char;
}
S[M] = '\0';
int max_score = 0;
for (int i = 0; i < N; i++){
int current_score = 0;
for (int j = 0; j < M; j++){
if (S[j] == T[i][j]) {
current_score++;
}
}
if (current_score > max_score){
max_score = current_score;
}
}
printf("%d\n", max_score);
}
int main() {
int Tc;
scanf("%d", &Tc);
while (Tc--) {
solve();
}
return 0;
}
Information
- Submit By
- Type
- Submission
- Problem
- P1164 Simple character matching game
- Contest
- Brain Booster #8
- Language
- C99 (GCC 13.2.0)
- Submit At
- 2025-02-17 15:40:52
- Judged At
- 2025-02-17 15:40:52
- Judged By
- Score
- 0
- Total Time
- 0ms
- Peak Memory
- 0 Bytes