Submission #613034

#TimeUsernameProblemLanguageResultExecution timeMemory
613034czhang2718HicCup (FXCUP4_hiccup)C++17
Compilation error
0 ms0 KiB
#include "hiccup.h" using namespace std; #include "bits/stdc++.h" int HicCup(std::string S) { int n = S.size(); auto check=[&](int x){ stack<char> s; int cur=0; for(int i=0; i<n; i++){ if(s[i]=='!'){ cur++; if(cur==x){ if(s.size()<2) return 0; char c=s.top(); s.pop(); char h=s.top(); s.pop(); if(c!='C' && h!='H') return 0; } cur=0; } if(s[i]=='C'){ if(cur) return 0; s.push('C'); } if(s[i]=='H'){ if(cur) return 0; s.push('H'); } } while(!s.empty()){ char c=s.top(); s.pop(); if(c!='!') return 0; } return 1; }; int x=0; for(int i=19; i>=0; i--){ if(x+(1<<i)<n && check(x+(1<<i))) x+=(1<<i); } if(!check(x)) return -1; return x; }

Compilation message (stderr)

hiccup.cpp: In lambda function:
hiccup.cpp:12:8: error: no match for 'operator[]' (operand types are 'std::stack<char>' and 'int')
   12 |    if(s[i]=='!'){
      |        ^
hiccup.cpp:22:8: error: no match for 'operator[]' (operand types are 'std::stack<char>' and 'int')
   22 |    if(s[i]=='C'){
      |        ^
hiccup.cpp:26:8: error: no match for 'operator[]' (operand types are 'std::stack<char>' and 'int')
   26 |    if(s[i]=='H'){
      |        ^