i am doing a codeforces problem and i dont know how to fix my implementation.
it is called dreamoon and wifi
here is my code:
#include <bits/stdc++.h>
using namespace std;
int choose(int n, int k){
if (k == 0){
return 1;
}
return (n * choose(n - 1, k - 1)) / k;
}
int main() {
string a, b;
getline(cin, a);
getline(cin, b);
double ans;
int realmove, fakemove, questions, howmove, works, all, num, breh;
vector<int> storeMove;
realmove = 0;
for(int i = 0; i<a.length(); i++) {
if(a.at(i) == '+'){
realmove++;
}
else{
realmove--;
}
}
fakemove = 0;
questions = 0;
for(int i = 0; i<a.length(); i++) {
if(b.at(i) == '+'){
fakemove++;
}
if(b.at(i) == '-'){
fakemove--;
}
if(b.at(i) == '?'){
questions++;
}
}
if(questions==0){
cout<<"";
if(fakemove != realmove){
cout << "0" << "\n";
}
else{
cout << "1\n";
}
}
else{
all = 1;
breh = questions;
for(int i = 0; i < questions; i++){
all = all*2;
}
for(int i = 0; i < all; i++){
if(questions!=abs(realmove-fakemove)){
questions--;
num++;
}
}
if(num > breh){
cout << "0" << endl;
return 0;
}
works = choose(breh, double(num)/2);
ans = double(works)/double(all);
cout << std::setprecision(0);
cout << ans << "\n";
}
return 0;
}
does anyone know how to fix this?