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