感谢您提供了修改后的代码。我注意到在定义字符数组 a 时,您使用了大括号 {} 将字符串括起来,这是导致程序无法正确输出结果的原因之一。在 C 语言中,使用双引号 "" 来定义字符串,不需要额外的大括号。
另外,修改后的代码中还有几处逻辑错误和小问题。我已经帮您进行了修正和优化,以下是修改后的代码:
#include <stdio.h>
#include <string.h>
void Longest(char a[]) {
int count = 0, maxCount = 0;
int sign = 0, maxStart = 0;
for (int i = 0; i < strlen(a);) {
if ((a[ i] >= 'a' && a[ i] <= 'z') || (a[ i] >= 'A' && a[ i] <= 'Z')) {
int num = 1;
for (int j = i; j < strlen(a);) {
if ((a[j + 1] >= 'a' && a[j + 1] <= 'z') || (a[j + 1] >= 'A' && a[j + 1] <= 'Z')) {
j++;
num++;
} else {
if (num > count) {
count = num;
sign = i;
}
i = i + num - 1;
break;
}
}
} else {
i++;
}
}
printf("最长的单词有 %d 位,是:", count);
for (int i = sign; i < sign + count; i++) {
printf("%c", a[ i]);
}
printf("\n");
}
int main(void) {
char a[1000] = "Graph convolutional networks (GCNs) have been widely used and achieved remarkable results in skeleton-based action recognition. In GCNs, graph topology dominates feature aggregation and therefore is the key to extracting representative features. ln this work,we propose a novel Channel-wise Topology Refinement Graph Convolution (CTR-GC) to dynamically learn different topologies and effectively aggregate joint features in different channels for skeleton-based action recognition. The proposed CTR-GC models channel-wise topologies through learning a shared topology as a generic prior for all channels and re-fining it with channel-specific correlations for each channel. Our refinement method introduces few extra parameters and significantly reduces the difficulty of modeling channel-wise topologies.";
Longest(a);
return 0;
}
在修正后的代码中,主要进行了以下改进:
1. 移除了字符数组 a 定义时的多余大括号。
2. 修正了变量的命名和作用域,以保证正确的结果输出。
3. 优化了循环和条件语句的结构,以提升代码的可读性和效率。
现在,修改后的代码应该能够正确输出字符串中最长的单词及其长度。希望对您有所帮助!如果还有其他问题,请随时提问。
如果问题已经解决,请设置最佳答案 |