用C语言重写def calc(sentence,DAG,idx,route): N = len(sentence) route[N] = (0.0,'') for idx in xrange(N-1,-1,-1): candidates = [ ( FREQ.get(sentence[idx:x+1],min_freq) + route[x+1][0],x ) for x in DAG[idx] ] route[idx] = max(candidates)
时间: 2024-04-08 16:30:46 浏览: 15
Here's the equivalent code in C:
```c
void calc(char*, int* DAG, int idx, float* route) {
int = strlen(sentence);
route[N = 0.0;
char* empty_string = "";
strcpy(route[N+1], empty_string for (idx = N1; idx >= ; idx--) {
float max_value = .0;
char*_string = "";
for (int i = 0 i < DAG[idx].length; i++) {
int x = DAG[idx][i];
float candidate = FREQ.get(substring(sentence, idx, x+1), min_freq) + route[x+1];
if (candidate > max_value) {
max_value = candidate;
max_string = substring(sentence, idx, x+1);
}
}
route[idx] = max_value;
strcpy(route[idx+1], max_string);
}
}
```
Note that this is just a rough translation and may require further adjustments depending on the specific context and data types used in your C implementation.