gpt4 book ai didi

C - 无法向前迭代第二个字符串

转载 作者:行者123 更新时间:2023-11-30 21:44:34 27 4
gpt4 key购买 nike

谁能告诉我我在这里做错了什么吗?

问题陈述: https://practice.geeksforgeeks.org/problems/good-or-bad-string/0

我的代码:

#include <stdio.h>
#include<string.h>
int is_vowel(char a) {
if(a==97||a==101||a==105||a==111||a==117){
return(1);
}
return(0);
}
int main() {
//code
int t,i;
scanf("%d",&t);
for(i=0;i<t;i++){
char str[100];
scanf("%s",str);
printf("%s",str);
int c_cnsnt=0;
int c_vwl=0;
int g_b=1;//suppose good
for(int j=0;j<strlen(str);j++){
//("%c",str[j]);
int num=is_vowel(str[j]);
printf("Debug %c %d %d\n",str[j],num,strlen(str));
if(is_vowel(str[j])) {
c_vwl++;
}
else { c_cnsnt++;}
if(c_vwl==c_cnsnt){
c_cnsnt=0;
c_vwl=0;
}
else {
if(c_vwl>5||c_cnsnt>=3){
g_b=0;
break;
}
}

}
printf("%d\n",g_b);
}

return 0;
}

示例

输入:

2
aeioup??
bcdaeiou??

输出:

1
0

我的解决方案链接:

https://code.hackerearth.com/9bca55K

为什么 for 循环对第二个字符串不起作用?

最佳答案

提示:您必须在增加另一个(例如 {c_vwl++;c_cnsnt=0;})后清除辅音和元音计数,而不是在它们相等时清除,并且始终测试您的 BAD 条件.

我不会给你示例代码。祝你好运

关于C - 无法向前迭代第二个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47691628/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com