Rebased projecteuler folder, now includes all contest programming stuff
This commit is contained in:
40
google/kickstart/2021roundA/a.cpp
Normal file
40
google/kickstart/2021roundA/a.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cmath>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void run_case(int test_case){
|
||||
int n, k;
|
||||
string s;
|
||||
|
||||
cin >> n >> k;
|
||||
cin >> s;
|
||||
|
||||
int result = 0;
|
||||
|
||||
auto ti = s.end() - 1;
|
||||
int l = s.length();
|
||||
for(auto it = s.begin(); it != s.begin() + l/2; ++it){
|
||||
if((*it) != (*ti)){
|
||||
result++;
|
||||
}
|
||||
--ti;
|
||||
}
|
||||
cout << "Case #" << test_case << ": " << abs(k - result) << endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(){
|
||||
ios::sync_with_stdio(0);
|
||||
cin.tie(0);
|
||||
|
||||
int t;
|
||||
cin >> t;
|
||||
|
||||
for(int tc = 1; tc <= t; ++tc){
|
||||
run_case(tc);
|
||||
cout << flush;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user