DOUBT : getting SEGMENTATION fault

Revision en2, by vishwalization, 2024-07-03 23:36:58

`#include <bits/stdc++.h> using namespace std;

define ln '\n'

typedef long long ll; typedef unsigned long long ull; typedef long double ld;

string s; string cur_path; int net; map<char, int> mp; map<int, char> goes_through;

// checks if the path goes through few dir given in string bool is_goes_through(){

for(auto x: goes_through){
    if (cur_path[x.first] != x.second){
       return 0;
    }
}
return 1;

}

int rec(int level){

// base case 
if (level == 48){
    if (net == -6 && is_goes_through()){
       return 1;
    }
}

int ans = 0;

// recursive case
for(auto x: mp){

    cur_path.push_back(x.first);
    net += mp[x.first];
    ans += rec(level + 1);
    cur_path.pop_back();   
    net -= mp[x.first];
}

return ans;

}

void solve(){

cin>>s;

mp['D'] = -1;
mp['U'] = 1;
mp['R'] = 2;
mp['L'] = -2;

for(int i=0; i< s.length(); i++){
    if (s[i] != '?'){
       goes_through[i] = s[i];
    }
}

for(auto x: goes_through) cout<<"idx = "<<x.first<<" dir = "<<x.second<<ln;

// cout<<rec(0)<<ln;

}

signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll t=1; // cin>>t; while(t--) solve(); }`

Tags #doubt, #recursion, paths

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English vishwalization 2024-07-03 23:38:33 41
en2 English vishwalization 2024-07-03 23:36:58 222
en1 English vishwalization 2024-07-03 23:25:06 1365 Initial revision (published)