【发布时间】:2016-01-10 16:48:33
【问题描述】:
/*
*
*Program for finding total number of holes in a string.
*For example total number of holes in "ANUBHAV" is 4 and in "GOURAV" is 3
*
*/
#include <stdio.h>
#include<string.h>
// start of main function
int main(void) {
int t,i = 0,hole = 0; // variable declaration
` char str[100];
scanf("%d",&t); // input number of test cases
while(t--)
{
scanf("%s",str); // input string
while(i < strlen(str))
{
if(str[i] == 'B')
{
hole += 2;
}
else if(str[i] == 'A' || str[i] == 'D' || str[i] == 'O' || str[i] == 'P' || str[i] == 'Q' || str[i] == 'R' )
{
hole += 1;
}
i = i + 1;
}
printf("%d",hole); //printing the total number of holes
}
return 0;
}
此代码在第一个测试用例(t)中正确输出,但在下一个测试用例中产生错误输出。代码中有什么问题? 请帮忙! 提前致谢!
【问题讨论】:
-
代码应该做什么?
-
可能是因为您的
main函数中有一个杂散的反引号...
标签: c string loops ide codeblocks