#include "hiccup.h"
#include <iostream>
using namespace std;
int HicCup(std::string S) {
int N = S.size();
int h = 0;
int c = 0;
int x = 0;
if (N==0) return 0;
if (S[0] != 'H') return -1;
{
int cur = 0;
char ex = S[0];
for(int i = 1 ; i < N;i++) {
const char &s = S[i];
if((s != 'H') && (s!='C') && (s!='!')){
return -1;
}
switch(ex) {
case 'H':
if(s=='H') cur++;
else if(s=='!') return -1;
break;
case 'C':
if(s=='H') cur++;
else if(s=='C') cur--;
break;
case '!':
if(s=='H') cur++;
else if(s=='C') cur--;
break;
default:
return -1;
break;
}
if(cur<0) return -1;
ex = s;
}
if(ex=='H' || cur != 0) return -1;
}
for(int i=0;i<N;i++){
if(S[i] == 'H') h++;
if(S[i] == '!') x++;
if(S[i] == 'C') c++;
}
return (x/h);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Incorrect |
6 ms |
512 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Incorrect |
6 ms |
512 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |