Problem My approach was to keep the multiplication factors in stack and pop them when a bracket ends
code
Please Help I am unable to find the mistake
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3792 |
| 2 | VivaciousAubergine | 3647 |
| 3 | jiangly | 3631 |
| 4 | Kevin114514 | 3574 |
| 5 | maroonrk | 3521 |
| 6 | strapple | 3515 |
| 7 | Radewoosh | 3461 |
| 8 | tourist | 3428 |
| 9 | turmax | 3378 |
| 10 | Um_nik | 3376 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 162 |
| 2 | adamant | 148 |
| 3 | Um_nik | 146 |
| 4 | Dominater069 | 143 |
| 5 | errorgorn | 140 |
| 6 | cry | 138 |
| 7 | Proof_by_QED | 136 |
| 8 | YuukiS | 135 |
| 9 | chromate00 | 134 |
| 10 | soullless | 133 |
Help in third problem of google kickstart round B
Problem My approach was to keep the multiplication factors in stack and pop them when a bracket ends
//JSD
#include<iostream>
#include<map>
#include<stack>
#define ll long long
#define Maxx (long long)1e9
using namespace std;
void solve(int test){
string s;
cin>>s;
int n=s.length();
stack<int> st;
int factor=1;
map<char, int > m;
for(int i=0;i<n;i++){
if(isdigit(s[i])){
st.push(int(s[i]-'0'));
factor*=int(s[i]-'0');
}
if(s[i]==')'){
int x=st.top();
st.pop();
factor/=x;
}
if(isalpha(s[i])){
m[s[i]]+=factor;
}
}
ll x=0,y=0;
x=(x+m['S'])%Maxx;
x=(x-m['N']+Maxx)%Maxx;
y=(y+m['E'])%Maxx;
y=(y-m['W']+Maxx)%Maxx;
cout<<"Case #"<<test<<": "<<y+1<<" "<<x+1<<"\n";
}
int main(){
ll t;
cin>>t;
int test=1;
while(t--){
solve(test);
test++;
}
return 0;
}
Please Help I am unable to find the mistake
| Name |
|---|


