B : magic
Score : 90->100
Diff : 1
Comment :
Examing : Easy.
After Examing : ???
Aft. : OHHHHHH:
#include
using namespace std;
int main() {
freopen("coin.in", "r", stdin);
freopen("coin.out", "w", stdout);
int l;cin >> l;
string seq;cin >> seq;
string re_seq;
char head=seq[0];
for (int i=1;i<l;i++) {
if (seq[i]!=head) {
re_seq += head;
head = seq[i];
}
}
re_seq += head;
if (seq[l-1] != head) re_seq += seq[l-1];
if (re_seq[0] == '1') cout << re_seq.length();
else cout << re_seq.length() / 2 * 2;
return 0;
}
if (re_seq[0] == '1') cout << re_seq.length();
else cout << re_seq.length() / 2 * 2;
That should be :
if (re_seq[re_seq.length()-1] == '1') cout << re_seq.length();
else cout << re_seq.length()-1;
Finally: