s = "abc123def456"nums = ""for c in s: if c.isdigit(): nums += cresult = int(nums)print(result)用c语言
时间: 2024-05-31 12:08:33 浏览: 146
js代码-两数之和 输入:nums = [2,7,11,15], target = 9 输出:[0,1]
把Python代码转换为C语言代码如下:
#include <stdio.h>
#include <string.h>
int main() {
char s[] = "abc123def456";
char nums[100] = "";
int result = 0;
int i;
for (i = 0; i < strlen(s); i++) {
if (isdigit(s[i])) {
strncat(nums, &s[i], 1);
}
}
result = atoi(nums);
printf("%d", result);
return 0;
}
阅读全文