Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
string s;
while(t--){
cin>>s;
int a = 0, b = 0, c = 0;
for(auto i : s){
if(i == 'A'){
a++;
continue;
}
if(i == 'B'){
b++;
continue;
}
if(i == 'C'){
c++;
continue;
}
}
if(a + c == b){
cout<<"YES"<<endl;
continue;
}
cout<<"NO"<<endl;
}
}
Copy The Code &
Try With Live Editor
Input
6
ABACAB
ABBA
AC
ABC
CABCBB
BCBCBCBCBCBCBCBC
ABACAB
ABBA
AC
ABC
CABCBB
BCBCBCBCBCBCBCBC
Output
NO
YES
NO
NO
YES
YES
YES
NO
NO
YES
YES
Demonstration
Codeforcess Solution 1579-A A. Casimir's String Solitaire ,C++, Java, Js and Python ,1579-A,Codeforcess Solution