原始问题:
将Java代码转换为C++代码
#include <stdio.h>
#include <string.h>
int goodSubstrings(char *str) {
int count = 0;
int len = strlen(str);
for (int i = 0; i < len; i++) {
for (int j = i + 1; j <= len; j++) {
if (isdigit(str[i]) && isdigit(str[j])) {
count++;
} else {
break;
}
}
}
return count;
}
int main() {
printf("%d
", goodSubstrings("100"));
printf("%d
", goodSubstrings("10010"));
return 0;
}
Prev:"Java实现:计算特殊二叉树根节点值"