Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 06:03

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[C++]str.replace();

Discussion on [C++]str.replace(); within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
d3pr1's Avatar
 
elite*gold: 0
Join Date: May 2008
Posts: 763
Received Thanks: 115
[C++]str.replace();

-
d3pr1 is offline  
Old 11/16/2010, 15:41   #2
 
Shadow992's Avatar
 
elite*gold: 77
Join Date: May 2008
Posts: 5,430
Received Thanks: 5,878
Quote:
Originally Posted by d3pr1 View Post
Da ich mit dem anderen Thema in meinem Informatik kurs schon fertige habe hat der lehrer mir ne Aufgabe gegeben die ich zuhause lösen kann wenn ich möchte und ich möchte es tun
Aufgabe ist wiefolgt
Caesar Verschlüsslung wir sollen eigentlich nur eine machen nach wahl ich möchte aber wegen des lern effektes alle 3 machen

a) einfach ne verschiebung um x zeichen done
b eine vordefinierte zeichenreihe heißt a=l z=u usw
und da treten 1 fehler und ein problem auf
1. ich kapier str.replace befehl nicht ganz
2. ist es irgentwie möglich den abc string(der ja eigentlich auch nen array ist
durcheinader zu würfeln
problem liegt dabei eher in richtung wie checke ich ob er den bustaben schon vergeben hat





c ist man kann sein eigenes wort eingeben als beispiel elitepvpers dann
setz er das alphabet so um a=e b=l usw
denke wenn ich b kapiert habe das c dann nur noch coderei ist



ich bin für alle ansätze dankbar pseudo code teil code oder nen denkanstoß


mfg,
d3pr1
Ganz ehrlich, aber ich versteh gerade nicht was genau bei b zu tun ist, werde dir aber bei einem Problem helfen, dass ganz sicher auf dich zu kommen wird:
Wie überprüft man ob das Zeichen bereits ersetzt wurde und nicht nocheinmal ersetzt wird.
Bsp.
a=l, o=a, l=o

Würde man "Hallo" jetzt ganz "hirnlos" umwandeln lassen, so würde das so aussehen, die wichtige Stelle wird markiert:
Alle a's mit l's ersetzen:
Quote:
Hlllo
Alle o's mit a's erstezen:
Quote:
Hllla
Alle l's mit o's ersetzen:
Quote:
Hoooa
So und schon hat man einen Fehler, denn wenn man das Wort wieder entschlüsselt, käme das bei raus:
Quote:
Hlllo
Und wozu string.replace? Das frisst doch nur zusätzlich Zeit, so gehts doch auch:
PHP Code:
#include <iostream>
#include <string>
using namespace std;

string Encode(string text,string normal_chars,string encoded_chars);

int main()
{
    
string encoded=Encode("Hallo","aol","lao");
    
cout<<"Encoded: "<<encoded<<"\n";
    
string decoded=Encode(encoded,"lao","aol");
    
cout<<"Decoded: "<<decoded<<"\n";
}

string Encode(string text,string normal_chars,string encoded_chars)
{
    if (
normal_chars.length()==encoded_chars.length())
    {

        for (
long i=0;i<text.length();i++)
        {
            for (
short i2=0;i2<normal_chars.length();i2++)
            {
                if (
normal_chars[i2]==text[i])
                {

                    
text[i]=encoded_chars[i2];
                    break;

                }
            }
        }
        return 
text;
    }
    else return 
"";

Shadow992 is offline  
Old 11/16/2010, 17:21   #3
 
elite*gold: 42
Join Date: Jun 2008
Posts: 5,425
Received Thanks: 1,888
Das du bei so tollen Variabelnamen wie 'lol' nicht weiterkommst, wundert mich nicht :>
MoepMeep is offline  
Old 11/16/2010, 17:23   #4
 
d3pr1's Avatar
 
elite*gold: 0
Join Date: May 2008
Posts: 763
Received Thanks: 115
Quote:
Originally Posted by MoepMeep View Post
Das du bei so tollen Variabelnamen wie 'lol' nicht weiterkommst, wundert mich nicht :>
geändert
Quote:
Originally Posted by Shadow992 View Post
Ganz ehrlich, aber ich versteh gerade nicht was genau bei b zu tun ist, werde dir aber bei einem Problem helfen, dass ganz sicher auf dich zu kommen wird:
Wie überprüft man ob das Zeichen bereits ersetzt wurde und nicht nocheinmal ersetzt wird.
Bsp.
a=l, o=a, l=o

Würde man "Hallo" jetzt ganz "hirnlos" umwandeln lassen, so würde das so aussehen, die wichtige Stelle wird markiert:
Alle a's mit l's ersetzen:

Alle o's mit a's erstezen:

Alle l's mit o's ersetzen:


So und schon hat man einen Fehler, denn wenn man das Wort wieder entschlüsselt, käme das bei raus:


Und wozu string.replace? Das frisst doch nur zusätzlich Zeit, so gehts doch auch:


ja das mit h=o und o=l ist mir auch schon aufgefallen dachte jetzt an sowas wie

string.replace was ich immer noch net auf die reihe kriege ka why wäre nett wenn einer einfach mal nen schnellen code dafür zeigt
dachte jetzt an sowas wie
dachte jetzt an sowas
ausgabe[string.find('a')] = 'b'
d3pr1 is offline  
Old 11/16/2010, 18:46   #5
 
Shadow992's Avatar
 
elite*gold: 77
Join Date: May 2008
Posts: 5,430
Received Thanks: 5,878
Quote:
Originally Posted by d3pr1 View Post
geändert




ja das mit h=o und o=l ist mir auch schon aufgefallen dachte jetzt an sowas wie

string.replace was ich immer noch net auf die reihe kriege ka why wäre nett wenn einer einfach mal nen schnellen code dafür zeigt
dachte jetzt an sowas wie
dachte jetzt an sowas
ausgabe[string.find('a')] = 'b'
Falls es dir noch nicht aufgefallen ist, das obere Beispiel ist die erledigte Aufgabe c) und b) in einem...
Shadow992 is offline  
Old 11/16/2010, 19:38   #6
 
d3pr1's Avatar
 
elite*gold: 0
Join Date: May 2008
Posts: 763
Received Thanks: 115
ich bin dir auch dankbar für den fertigen code aber erstmal analysieren ^^
d3pr1 is offline  
Reply


Similar Threads Similar Threads
[Tut] how to replace items
04/25/2012 - Shaiya Hacks, Bots, Cheats & Exploits - 37 Replies
Im going to show you how to replace items npc have with what you want them to sell. Im going to use Losen Piettrei a weapon mechant in glitter to make a example 1. You must extract the data.saf file ( if you need to do this please take a look at the post to do it.) 2. You will need a Hex editor. Ok lets start Go to ur NPCQuest.SData located in ur client in the folder NPC. Open it with a hex editor.
[help] Object replace on the map
10/29/2010 - Metin2 Private Server - 0 Replies
hi com i have problems with my bad germany i just bad bad understand so i need help find out 1 program have ther on epvp this program generate the ids from objects for the people do or mod maps but i dont find that i know i have use it before but lost that p+rogram need find out he generate all id from the objects so we can use on the maps like houses walss etc can you guys give me a hand?
[help] i need replace the old jump..
10/12/2009 - CO2 Private Server - 2 Replies
where i find the jump inside client?? please; :confused:
Why cant I replace the pk2?
07/25/2009 - SRO Private Server - 2 Replies
Whenever I download babbes english sunsro pk2 and replace it, it always replaces it self to an older version and has to update back to 2.020 again, it does this with any other pk2..
replace blinding fc
05/25/2005 - Conquer Online 2 - 2 Replies
i tried hard to find a topic that did this but all i could find was a way to remove all the 3d effects. If it's been done before, sry (and feel free to delete topic). all this file does is replace lvl 2 fc's animation with that of lvl 1 (the plain star), and replace lvl 3 fc's animation (the blinding one) with that of lvl 2 (the growing yellow circle). REMEMBER TO ALWAYS MAKE A BACKUP FILE this file goes into <drive>:&#092;PATH_TO_CONQUER&#092;i ni&#092; (default i believe is c:&#092;Program Files&#092;Conquer...



All times are GMT +1. The time now is 06:04.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.