| Task: | Järjestys |
| Sender: | tonero |
| Submission time: | 2022-01-22 13:38:16 +0200 |
| Language: | C++ (C++17) |
| Status: | READY |
| Result: | 100 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 100 |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.01 s | details |
Compiler report
input/code.cpp: In function 'int main()':
input/code.cpp:28:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < s.size(); ++i){
~~^~~~~~~~~~
input/code.cpp:40:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = acnt; i < s.size(); ++i){
~~^~~~~~~~~~Code
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
string s;
getline(cin, s);
for (int i = 0; i < t; ++i){
int acnt = 0;
int bcnt = 0;
int swp1 = 0;
int swp2 = 0;
getline(cin, s);
for (int i = 0; i < s.size(); ++i){
if(s[i] == 'A'){
++acnt;
}else{
++bcnt;
}
}
for (int i = 0; i < acnt; ++i){
if(s[i] == 'B'){
++swp1;
}
}
for (int i = acnt; i < s.size(); ++i){
if(s[i] == 'A'){
++swp2;
}
}
int tot = (swp2+swp1)/2;
if(swp2 > swp1){
tot += swp2-swp1;
}
if(swp1 > swp2){
tot += swp1-swp2;
}
cout << tot << '\n';
}
flush(std::cout);
}