我有这个计数子字符串回文代码我想先扫描字符串然后打印子字符串
中回文总数的计数我尝试使用% I和%d,它只是显示主要错误
#include <stdio.h>
#include <string.h>
int countSubstrings(char * s)
{
int res = 0;
int left = 0;
int right = 0;
int len = strlen(s);
for (int i = 0; i < len; i++) {
left = i;
right = i;
while (left >= 0 && right < len && s[left] == s[right]) {
res++;
left--;
right++;
}
left = i;
right = i + 1;
while (left >= 0 && right < len && s[left] == s[right]) {
res++;
left--;
right++;
}
}
}
int main ()
{
int res = 0;
int len = strlen(s);
scanf ("%i", &len);
printf ("%d", res);
}
预期输入:
(words)
预期输出:
(the count of substring)
修改main函数如下:
int main (){
char s[100]; // If the maximum length of input is < 100.
scanf("%s",s);// It will scan standard input till whitespace
printf("%d",countSubstrings(s));
}