Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string resultatenbinaire = ""; mais changez le nom des variables pour pas que ce soit cramé qu'on ait la même chose
- string resultatenmorse = ""; svp
- string resultatenlettres = "";
- resultatenmorse = resultatenbinaire;
- for (g = 0; g < resultatenmorse.size();g++) { //This loop finds corresponding morse characters to binary digits sequences
- if (resultatenmorse.substr(g, 3) == "111") {
- resultatenmorse.replace(resultatenmorse.find("111"),3, "-" );
- }
- else if(resultatenmorse.substr(g, 1) == "1"){
- resultatenmorse.replace(resultatenmorse.find("1"), 1, ".");
- }
- else if (resultatenmorse.substr(g, 7) == "0000000") {
- resultatenmorse.replace(resultatenmorse.find("0000000"), 7, " / ");
- }
- else if (resultatenmorse.substr(g, 3) == "000") {
- resultatenmorse.replace(resultatenmorse.find("000"), 3, " ");
- }
- }
- for (g = 0; g < resultatenmorse.size();g++) {
- if (resultatenmorse.substr(g, 1) == "0") {
- resultatenmorse.replace(resultatenmorse.find("0"), 1, "");
- }
- }
- cout << "\n" << "l'équivalent en morse est : " << resultatenmorse;
- resultatenlettres = resultatenmorse;
- for (g = 0; g < resultatenlettres.size(); g++) {
- if (resultatenlettres.substr(g, 5) == "...--") {
- resultatenlettres.replace(resultatenlettres.find("...--"), 5, "3");
- }
- else if (resultatenlettres.substr(g, 5) == ".----") {
- resultatenlettres.replace(resultatenlettres.find(".----"), 5, "1");
- }
- else if (resultatenlettres.substr(g, 4) == ".-..") {
- resultatenlettres.replace(resultatenlettres.find(".-.."), 4, "L");
- }
- else if (resultatenlettres.substr(g, 4) == "-..-") {
- resultatenlettres.replace(resultatenlettres.find("-..-"), 4, "X");
- }
- else if (resultatenlettres.substr(g, 4) == "....") {
- resultatenlettres.replace(resultatenlettres.find("...."), 4, "H");
- }
- else if (resultatenlettres.substr(g, 4) == "-...") {
- resultatenlettres.replace(resultatenlettres.find("-..."), 4, "B");
- }
- else if (resultatenlettres.substr(g, 4) == "-.--") {
- resultatenlettres.replace(resultatenlettres.find("-.--"), 4, "Y");
- }
- else if (resultatenlettres.substr(g, 4) == ".---") {
- resultatenlettres.replace(resultatenlettres.find(".---"), 4, "J");
- }
- else if (resultatenlettres.substr(g, 4) == "-.-.") {
- resultatenlettres.replace(resultatenlettres.find("-.-."), 4, "C");
- }
- else if (resultatenlettres.substr(g, 3) == "..-") {
- resultatenlettres.replace(resultatenlettres.find("..-"), 3, "U");
- }
- else if (resultatenlettres.substr(g, 3) == "---") {
- resultatenlettres.replace(resultatenlettres.find("---"), 3, "O");
- }
- else if (resultatenlettres.substr(g, 3) == ".-.") {
- resultatenlettres.replace(resultatenlettres.find(".-."), 3, "R");
- }
- else if (resultatenlettres.substr(g, 3) == ".--") {
- resultatenlettres.replace(resultatenlettres.find(".--"), 3, "W");
- }
- else if (resultatenlettres.substr(g, 3) == "...") {
- resultatenlettres.replace(resultatenlettres.find("..."), 3, "S");
- }
- else if (resultatenlettres.substr(g, 2) == "..") {
- resultatenlettres.replace(resultatenlettres.find(".."), 2, "I");
- }
- else if (resultatenlettres.substr(g, 1) == ".") {
- resultatenlettres.replace(resultatenlettres.find("."), 1, "E");
- }
- else if (resultatenlettres.substr(g, 1) == "-") {
- resultatenlettres.replace(resultatenlettres.find("-"), 1, "T");
- }
- }
- for (g = 0; g < resultatenlettres.size(); g++) {
- if (resultatenlettres.substr(g, 3) == "/ ") {
- resultatenlettres.replace(resultatenlettres.find("/ "), 2, "");
- }
- else if (resultatenlettres.substr(g, 1) == " ") {
- resultatenlettres.replace(resultatenlettres.find(" "), 1, "");
- }
- }
- for (g = 0; g < resultatenlettres.size(); g++) {
- if (resultatenlettres.substr(g, 1) == "/") {
- resultatenlettres.replace(resultatenlettres.find("/"), 1, " ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement