mercredi 16 mai 2018

Encription scout code Reserve

All characters will shift as much as n characters by schema Normal: ABCDEFGHIJKLMNOPQRSTUVWXYZ Encrypted: XYZABCDEFGHIJKLMNOPQRSTUVW There is no difference between lowercase and uppercase, as the reference of all characters is lowercase, and otherwise the alphabet will not be encrypted.

#include <iostream>
#include <string>
#include <sstream>

using namespace std;
string convertToEnglish( string morse,  string const morseCode[]);

int main()
{
     string input = "";
     cout << "Please enter a string in morse code: ";
     getline( cin, input);

     string const morseCode[] = {".-", "-...", "-.-.", "-..", ".", "..-.",
    "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-",
    ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."};

     cout << convertToEnglish(input, morseCode) <<  endl;


    return 0;
}

 string convertToEnglish( string morse,  string const morseCode[])
{
     string output = "";
     string currentLetter = "";
     istringstream ss(morse);
        const char  characters[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};


    while(ss >> currentLetter)
    {
         size_t index = 0;
        while(currentLetter != morseCode[index] && index < 26)
        {
            ++index; //increment here so we don't have to decrement after the loop like if we put in the condition
        }

        output += 'a' + index;
    }

    return output;
}

It is correct or not ? but Isn't work like the question

Aucun commentaire:

Enregistrer un commentaire