对象已移动

可在此处找到该文档 Generate all possible strings formed by replacing letters with given respective symbols – New Self New Life
New Self New Life
No Result
View All Result
  • Home
  • Entertainment
  • Celebrity
  • Cinema
  • Music
  • Digital Lifestyle
  • Social Media
  • Softwares
  • Devices
  • Home
  • Entertainment
  • Celebrity
  • Cinema
  • Music
  • Digital Lifestyle
  • Social Media
  • Softwares
  • Devices
New Self New Life
No Result
View All Result
Home Softwares

Generate all possible strings formed by replacing letters with given respective symbols

by admin
4 years ago
in Softwares
Best Coding Practices For Rest API Design
Share on FacebookShare on Twitter


Given a string S consisting of N characters and an array M[] of pairs of characters such that any character M[i][0] may be changed with the character M[i][1] within the string S, the duty is to generate all of the doable strings shaped by changing some characters of the string with their respective symbols within the array M[].

Examples:

Enter: S = “aBc”, M = {‘a’ : ‘$’, ‘B’ : ‘#’, ‘c’ : ‘^’}
Output:
aBc
aB^
a#c
a#^
$Bc
$B^
$#c
$#^ 

Enter: S = “a”, M={‘a’ : ‘$’}
Output:
a
$

Strategy: The given downside may be solved by utilizing Backtracking to generate all doable strings by changing every character with the mapped character within the array M[]. Comply with the steps beneath to resolve the issue:

  • Retailer all of the pairs of the mapped characters within the array M[] in a map, say Map.
  • Outline a recursive perform say generateLetters(S, P), the place S is the modified string and P is the index of the present character:
    • Test for the bottom case i.e., if index P equals to the N then print the string S and return.
    • Don’t change the present character and recursively name for the perform, generateLetters(S, P + 1).
    • Now, change the character, S[P] with the respective image within the map M and name for the perform, generateLetters(S, P+1).
  • After finishing the above steps, name for the perform generateLetters(S, 0) to print all doable strings.

Under is the implementation of the above method:

C++

  

#embrace <bits/stdc++.h>

utilizing namespace std;

  

void generateLetters(string S, int P,

                     unordered_map<char, char> M)

{

    

    if (P == S.measurement()) {

        cout << S << "n";

        return;

    }

  

    

    

    generateLetters(S, P + 1, M);

  

    

    S[P] = M[S[P]];

  

    

    

    generateLetters(S, P + 1, M);

  

    return;

}

  

int foremost()

{

    string S = "aBc";

    unordered_map<char, char> M;

    M['a'] = '$';

    M['B'] = '#';

    M['c'] = '^';

    M['d'] = '&';

    M['1'] = '*';

    M['2'] = '!';

    M['E'] = '@';

  

    

    generateLetters(S, 0, M);

  

    return 0;

}

Output:


aBc
aB^
a#c
a#^
$Bc
$B^
$#c
$#^

Time Complexity: O(N*2N)
Auxiliary House: O(1)

Consideration reader! Don’t cease studying now. Pay money for all of the vital DSA ideas with the DSA Self Paced Course at a student-friendly value and change into business prepared.  To finish your preparation from studying a language to DS Algo and plenty of extra,  please refer Full Interview Preparation Course.

In case you want to attend dwell courses with specialists, please refer DSA Stay Lessons for Working Professionals and Aggressive Programming Stay for College students.



Source link

Tags: formedGeneratelettersreplacingrespectivestringssymbols
Previous Post

Space Jam 2 Tops Weekend Box Office With Surprise $32 Million

Next Post

DARKSIDE ‘Spiral’ album | Nicolás Jaar and Dave Harrington

Related Posts

Start up crash fix – Vivaldi iOS Browser snapshot 3737.4
Softwares

Start up crash fix – Vivaldi iOS Browser snapshot 3737.4

by admin
June 30, 2025
Windows’ infamous ‘blue screen of death’ will soon turn black
Softwares

Windows’ infamous ‘blue screen of death’ will soon turn black

by admin
June 28, 2025
User Guide for Unopim Odoo Connector
Softwares

User Guide for Unopim Odoo Connector

by admin
June 27, 2025
Warp 2.0 evolves its terminal experience into an Agentic Development Environment
Softwares

Warp 2.0 evolves its terminal experience into an Agentic Development Environment

by admin
June 25, 2025
10+ Best Text Animation Presets & Templates for Premiere Pro — Speckyboy
Softwares

10+ Best Text Animation Presets & Templates for Premiere Pro — Speckyboy

by admin
June 29, 2025
Next Post
DARKSIDE ‘Spiral’ album | Nicolás Jaar and Dave Harrington

DARKSIDE 'Spiral' album | Nicolás Jaar and Dave Harrington

Object.entries

Dark Mode in One Line of Code!

  • Trending
  • Comments
  • Latest
Torras Ostand O3 Air iPhone case review – It runs rings around other cases

Torras Ostand O3 Air iPhone case review – It runs rings around other cases

May 21, 2025
Indiana Evans: What happened to the H2O Australian actress Indiana Evans and what is she doing now? | Explainer

Indiana Evans: What happened to the H2O Australian actress Indiana Evans and what is she doing now? | Explainer

December 7, 2024
I Tried Calocurb For 90 Days. Here’s My Review.

I Tried Calocurb For 90 Days. Here’s My Review.

January 8, 2025
Aaron Rodgers returns to ‘Pat McAfee Show’ 1 day after being axed by host – National

Aaron Rodgers returns to ‘Pat McAfee Show’ 1 day after being axed by host – National

January 11, 2024
18 Best Political Series on Netflix, Ranked

18 Best Political Series on Netflix, Ranked

March 25, 2025
Bones: All Of Brennan’s Interns, Ranked

Bones: All Of Brennan’s Interns, Ranked

June 15, 2021
GitHub Enterprise Server 3.13.3 tackles critical SAML vulnerability

GitHub Enterprise Server 3.13.3 tackles critical SAML vulnerability

August 23, 2024
How to Build a DIY Spotify Music Player with Raspberry Pi Pico

How to Build a DIY Spotify Music Player with Raspberry Pi Pico

May 13, 2025
On the road with Saya Gray

On the road with Saya Gray

June 30, 2025
Microscopic Simulation in Transportation: A Clear Guide

Microscopic Simulation in Transportation: A Clear Guide

June 30, 2025
Rihanna’s sheer baby doll lingerie look is bang on trend for SS25

Rihanna’s sheer baby doll lingerie look is bang on trend for SS25

June 30, 2025
X Will Soon Charge for Ads Based on the Size of Your Visuals

X Will Soon Charge for Ads Based on the Size of Your Visuals

June 30, 2025
Family’s ‘Shock and Horror’ After Son’s Body at Funeral Infested with ‘Moving and Visible Maggots’: Suit

Family’s ‘Shock and Horror’ After Son’s Body at Funeral Infested with ‘Moving and Visible Maggots’: Suit

June 30, 2025
Korean & Spanish Shows Win Big At Italian Global Series Festival

Korean & Spanish Shows Win Big At Italian Global Series Festival

June 29, 2025
‘Ironheart’ Makes a Major Pivot From the Comics With This One Change

‘Ironheart’ Makes a Major Pivot From the Comics With This One Change

June 29, 2025
WhatsApp Banned From U.S. House Devices Over Security Concerns

WhatsApp Banned From U.S. House Devices Over Security Concerns

June 29, 2025
New Self New Life

Your source for entertainment news, celebrities, celebrity news, and Music, Cinema, Digital Lifestyle and Social Media and More !

Categories

  • Celebrity
  • Cinema
  • Devices
  • Digital Lifestyle
  • Entertainment
  • Music
  • Social Media
  • Softwares
  • Uncategorized

Recent Posts

  • On the road with Saya Gray
  • Microscopic Simulation in Transportation: A Clear Guide
  • Rihanna’s sheer baby doll lingerie look is bang on trend for SS25
  • Home
  • Disclaimer
  • DMCA
  • Privacy Policy
  • Cookie Privacy Policy
  • Terms and Conditions
  • Contact us

Copyright © 2021 New Self New Life.
New Self New Life is not responsible for the content of external sites. slotsfree  creator solana token

No Result
View All Result
  • Home
  • Entertainment
  • Celebrity
  • Cinema
  • Music
  • Digital Lifestyle
  • Social Media
  • Softwares
  • Devices

Copyright © 2021 New Self New Life.
New Self New Life is not responsible for the content of external sites.

New Self New Life