266(A,cpp): solve “Stones on the Table”

Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2023-07-10 09:53:58 +02:00
parent 5013af5dcb
commit 85ccacae44
Signed by: mfocko
GPG key ID: 7C47D46246790496
2 changed files with 1103 additions and 0 deletions

68
266/a.cpp Normal file
View file

@ -0,0 +1,68 @@
#include <iostream>
#include <string>
namespace {
using namespace std;
int remove(const std::string& s) {
int counter = 0;
for (auto i = 0; i < s.size() - 1; ++i) {
if (s[i] == s[i + 1]) {
++counter;
}
}
return counter;
}
void solve() {
int size;
cin >> size;
std::string line;
cin >> line;
cout << remove(line) << "\n";
}
} // namespace
// for single test case, comment out for N test cases
#define SINGLE
#ifndef TEST
int main(void) {
#ifdef SINGLE
solve();
#else
// for multiple test cases
int N;
std::cin >> N >> std::ws;
for (auto i = 0; i < N; ++i) {
solve();
}
#endif
return 0;
}
#else
#include "../.common/cpp/catch_amalgamated.hpp"
TEST_CASE("examples") {
CHECK(remove(std::string("RRG")) == 1);
CHECK(remove(std::string("RRRRR")) == 4);
CHECK(remove(std::string("BRBG")) == 0);
}
#endif

1035
266/index.html Normal file

File diff suppressed because it is too large Load diff