fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main(){
  5. int t;
  6. cin >> t;
  7. while(t--){
  8. int z, osoby = 0;
  9. cin >> z;
  10. while(z--){
  11. string czujnik;
  12. cin >> czujnik;
  13. if(czujnik == "AI") {
  14. osoby++;
  15. }
  16. else if(czujnik == "BI") {
  17. osoby++;
  18. }
  19. else if(czujnik == "AO") {
  20. osoby--;
  21. }
  22. else if(czujnik == "BO") {
  23. osoby--;
  24. }
  25. if(osoby < 0) {
  26. cout<<"ERROR";
  27. break;
  28. }
  29. }
  30. cout << osoby;
  31. }
  32. }
Success #stdin #stdout 0s 5380KB
stdin
1
7
AI
BO
BI
BI
AO
AI
AO
stdout
1