log in
About and Contact
© 2020 DOUBTCOOL
python code solution :-
for t in range(int(input())): a,b,c,x=0,0,'',0 s=input() for i in range(len(s)): if s[i]=="A": a+=1 if c=="A": a+=x else: c="A" x=0 if s[i]=="B": b+=1 if c=="B": b+=x else: c="B" x=0 if s[i]==".": x+=1 print(a,b)
C program solution
#include <stdio.h> int main(){ int t; scanf("%d", &t); // Reading input from STDIN while(t--) { char s[100]; int ca=0,cb=0; scanf("%s", &s); // Writing output to STDOUT int len = strlen(s); for(int i=0; i<len ;i++) { if(s[i]=='A') { ca+=1; int l=1; while(s[i+1] == '.') { l++; } if(s[i+1] == 'A') { ca+=l-1; } i+=l-1; } else if(s[i]=='B') { cb+=1; int l=1; while(s[i+l]=='.') { l++; } if(s[i+1]=='B') { cb+=l-1; } i+=i+l-1; } } printf("%d %d \n",ca, cb); } //return 0; }
for t in range(int(input())): a,b,c,x=0,0,'',0 s=input() for i in range(len(s)): if s[i]=="A": a+=1 if c=="A": a+=x else: c="A" x=0 if s[i]=="B": b+=1 if c=="B": b+=x else: c="B" x=0 if s[i]==".": x+=1 print(a,b)