0
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
int t,n,x,i,j;
char st[50];
scanf("%d",&t);
for(i=0;i<t;i++)
{
scanf("%d %d",&n,&x);
for(j=0;j<n;j++)
{
scanf("%c",&st[j]);
if(st[j]=='A')
x=x*1;
if(st[j]=='B')
x=x*-1;
}
printf("%d",x);
}
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
return 0;
}
输入代码的格式为:C程序不采取输入正确和producding错误输出
t
n x
some_string_having_A_and_B
样品:
1
3 10
ABA
预期输出
-10
实际产量
10
此代码给-10
如果B
数为奇数和10
如果B
数为偶数。我知道编写程序的正确和最佳方式,但我无法弄清,为什么这个代码产生错误的输出。
尝试打印'在环路'ST [j]的值。 – Barmar