mirror of
https://gitlab.com/mfocko/Codeforces.git
synced 2024-12-21 13:41:22 +01:00
266(A,cpp): solve “Stones on the Table”
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
5013af5dcb
commit
85ccacae44
2 changed files with 1103 additions and 0 deletions
68
266/a.cpp
Normal file
68
266/a.cpp
Normal 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
1035
266/index.html
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue