问题分析: 首先,您的代码存在一些语法和逻辑错误。在代码中,您试图通过将一个字符数组传递给
Longest函数来查找最长的单词,但是您在循环中的许多地方使用了错误的方式来访问和操作字符数组。
代码修改建议:
1. 在C语言中,单个字符的ASCII值应该使用单引号(')括起来,而不是双引号(\)。例如,应该使用
'A'而不是
\A\。
2. 在字符的ASCII范围判断部分,您应该使用单引号括起字符,例如
a >= 'A' && a <= 'Z'。
3. 在循环部分,您应该使用
for循环而不是
while循环,并且应该正确地增加循环变量。
4. 在内部循环中,您应该使用正确的循环条件来遍历一个单词,例如使用
while(a[j+1] >= 'A' && a[j+1] <= 'Z' || a[j+1] >= 'a' && a[j+1] <= 'z')。
5. 最后,在返回之前,应该将
i增加以便继续扫描字符串。
以下是经过修正的代码:
- #include <stdio.h>
- #include <string.h>
- void Longest(char a[]) {
- int count = 0, sign = 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 = j + 1;
- break;
- }
- }
- } else {
- i++;
- }
- }
- printf(\最长的单词有 %d 位,是:%.*s\
- \, count, count, &a[sign]);
- }
- 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;
- }
复制代码
注意: 请确保对于输入字符串中的标点符号和空格,您的代码也需要进行适当的处理,以避免将它们包含在单词长度的计算中。以上代码只是修复了原始代码的问题,仍然需要进一步优化以处理更复杂的文本。