Compile Error
foo.cc: In function 'int main()': foo.cc:28:17: error: 'ans' was not declared in this scope; did you mean 'abs'? 28 | ans = min(cnt0 / 2, cnt1 / 2); | ^~~ | abs
Code
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
int t, n;
cin >> t;
while (t-- && cin >> n)
{
string s;
cin >> s;
string p = s;
sort(p.begin(), p.end());
int cnt0 = 0;
int cnt1 = 0;
for (int i = 0; i < s.size(); i++)
{
cnt0 += (s[i] != p[i]);
}
reverse(p.begin(), p.end());
for (int i = 0; i < s.size(); i++)
{
cnt1 += (s[i] != p[i]);
}
ans = min(cnt0 / 2, cnt1 / 2);
cout << ans << "\n";
}
}
Information
- Submit By
- Type
- Pretest
- Problem
- P1016 Swap sort
- Language
- C++17 (G++ 13.2.0)
- Submit At
- 2023-12-28 14:37:40
- Judged At
- 2024-11-11 03:47:04
- Judged By
- Score
- 0
- Total Time
- 0ms
- Peak Memory
- 0 Bytes